Lesson 22: Prompt Chaining & Multi-Step Workflows
Break big tasks into focused prompts where each output feeds the next — with a full worked chain and validation checkpoints.
One Big Prompt vs. A Chain
A single giant prompt makes the model juggle too many jobs — it drifts, skips requirements, and wastes tokens re-reading context. Prompt chaining splits the job into focused steps, each with a clean input and output.
The Pattern
Step 1 (research) -> output: topic list
Step 2 (select) -> output: one topic + outline
Step 3 (draft) -> output: full draft
Step 4 (polish) -> output: final text
Each step's output becomes the next step's input — and you can review or redirect between steps.
Worked Example: LinkedIn Post
Step 1 — generate angles:
List 10 trending AI topics for 2026 for a LinkedIn audience of developers.
→ agentic AI, multimodal models, AI coding agents, …
Step 2 — pick and outline:
Expand topic #1 (agentic AI) into a 4-point outline: what it is,
why it matters in 2026, key players, how to learn it.
→ outline with 4 points
Step 3 — draft:
Write a 150-word LinkedIn post from this outline. Hook line first.
→ draft
Step 4 — polish:
Tighten this draft: remove filler, punch up the hook, keep it under 150 words.
→ final post
Why Chaining Wins
| One giant prompt | Chained prompts | |
|---|---|---|
| Context per step | Huge, diluted | Small, focused |
| Failure point | One big failure | Catch errors between steps |
| Token cost | Re-reads everything | Each step is lean |
| Control | Little | Redirect at any step |
Validation Checkpoints
Insert a validation step where errors are likely:
Step 2.5 (validation): Check the outline — does it cover all 4 required
points? If not, list what's missing before continuing.
Validation catches issues early instead of letting them propagate through the whole chain.
Branching Chains
Some workflows split into parallel paths that merge later:
Analyze competitors A, B, and C in parallel
-> three separate analyses
Merge: "Synthesize these three competitor analyses into one
comparison table with a recommendation."
Common Mistakes
- Chains with no review step — errors compound silently.
- Over-chaining simple tasks — one prompt is fine for a one-liner.
- Forgetting to pass the previous output — each prompt must include it.
Key Takeaways
- Chain = focused steps with clean inputs/outputs + review points.
- Validation checkpoints stop errors from propagating.
- Use branching chains for parallel work that merges later.
- Over-chaining simple tasks wastes tokens — match the chain to the task.
Next up: Real-world playbook — prompting for code, writing, safety, and evaluation.
# Prompt chaining: each step's output feeds the next prompt
topics = ["agentic AI", "multimodal models", "AI coding agents", "small language models",
"AI safety", "RAG", "on-device AI", "AI video", "voice AI", "AI + robotics"]
print("STEP 1 - 'List 10 trending AI topics for 2026':")
print(" ->", ", ".join(topics[:3]), "...\n")
picked = topics[0]
print(f"STEP 2 - 'Expand topic #1 ({picked}) into a 4-point outline':")
outline = ["What it is", "Why it matters in 2026", "Key players", "How to learn it"]
for i, item in enumerate(outline, 1):
print(f" {i}. {item}")Lesson Code (Python)
# Prompt chaining: each step's output feeds the next prompt
topics = ["agentic AI", "multimodal models", "AI coding agents", "small language models",
"AI safety", "RAG", "on-device AI", "AI video", "voice AI", "AI + robotics"]
print("STEP 1 - 'List 10 trending AI topics for 2026':")
print(" ->", ", ".join(topics[:3]), "...\n")
picked = topics[0]
print(f"STEP 2 - 'Expand topic #1 ({picked}) into a 4-point outline':")
outline = ["What it is", "Why it matters in 2026", "Key players", "How to learn it"]
for i, item in enumerate(outline, 1):
print(f" {i}. {item}")Console Output
STEP 1 - 'List 10 trending AI topics for 2026':
-> agentic AI, multimodal models, AI coding agents ...
STEP 2 - 'Expand topic #1 (agentic AI) into a 4-point outline':
1. What it is
2. Why it matters in 2026
3. Key players
4. How to learn itCode Visualization Tips
- Draw the chain as a conveyor belt: Step 1 → Step 2 → Step 3, with arrows labeled 'output → input'.
- Add a red checkpoint diamond between steps where validation runs.
- Draw a branching chain splitting into 3 parallel boxes that merge into one synthesis box.
Professional Tips & Tricks
- Name each step's output format ('return a numbered list') so the next step can parse it.
- Add a 'review before continuing' prompt between high-risk steps.
- Keep chains in code (a list of prompts) so you can re-run and version them.
Python Code Judge & Practice Arena
LeetCode StyleRun real Python 3.12 WebAssembly code directly in your browser against automated test suites.
Design a 4-Step Chain
Test Your Knowledge
Instant feedbackQuick Check: Prompt Chaining
Up next · Continue learning
Prompting for Code Generation
The CODE framework, before/after examples, and the mistakes that make AI write broken code.