Prompt chaining: decompose, verify each step
Prompt chaining splits a complex task into a fixed sequence of focused LLM steps, each feeding the next, with a deterministic check between them so one bad step can't poison the rest.
What it is
Prompt chaining breaks one complex task into a fixed sequence of small LLM steps, where each step's output becomes the next step's input. Instead of one giant prompt that does everything at once, you run several focused prompts in order.
- Each step has one job and one clear output.
- A deterministic check sits between steps to catch garbage before it propagates.
- The chain is fixed: same steps, same order, every run.
When to use it
Reach for it when a task naturally splits into stages that depend on each other.
- Multi-stage transforms: extract data, then validate it, then format it.
- Generate-then-refine: draft an answer, then rewrite it against a rubric.
- Anything you can't reliably get from one prompt because the model drops requirements or hallucinates structure.
Skip it when the task is genuinely one step, or when the path branches on the input — that's routing, not a fixed chain. Don't chain just to look sophisticated; each hop adds latency and cost.
How it works
You wire steps so each consumes the prior output, with a hard check between them.
- Step 1 extracts raw fields from a document, returning JSON.
- A check runs
JSON.parse(output)against a schema — if it fails, you retry or stop, you do not pass bad data forward. - Step 2 takes the validated fields and writes a summary.
- A check confirms the summary mentions every required field before it ships.
The checks are plain code, not more LLM calls. They are your guardrails between hops — deterministic, cheap, and they keep one bad step from poisoning the rest of the chain.
Watch out for
- Errors compound. A small mistake in step 1 becomes a confident wrong answer by step 4. The between-step checks exist precisely to stop this — don't skip them.
- Context drift. Each step only sees what you pass it; forget to forward a field and a later step invents one. Be explicit about what flows forward.
- Latency and cost stack. Four sequential calls means four round-trips. If steps are independent, you want parallelization instead.
- Over-decomposition. Splitting a trivial task into six prompts is slower and more fragile, not smarter. Chain only where a real dependency exists.
Related patterns
Routing: send each input to the right handler
Routing puts a thin classifier in front of your specialists — it inspects each input, picks the handler best suited to it, and dispatches without doing the work itself.
Reflection: let the agent critique its own output
Reflection runs your agent twice — generate, then critique against explicit criteria and feed the fixes back — so a weak first draft becomes a stronger final answer.
Planning: make a plan before acting
Make the agent write an explicit, ordered plan before it acts, execute the steps, and replan when reality breaks the plan.