Prompt Chaining
A fixed sequence of LLM calls with checks between steps. Predictable and debuggable.
Problem
One large prompt that asks a model to extract, analyze, decide and write all at once is hard to get right and harder to debug. When the output is wrong, you can’t tell which part of the job failed, and small prompt changes have unpredictable effects.
- Smaller, focused prompts are more accurate than one prompt doing everything.
- Each extra call adds latency and a place for errors to compound.
- Fixed steps are predictable but can’t adapt to unusual inputs.
- Teams need to test and improve each part independently.
Solution
Break the task into a fixed sequence of steps, each a separate LLM call with one job and a defined output format. Code, not the model, decides the order. Between steps, add gates: cheap programmatic checks such as schema validation, required fields or length limits. A failed gate stops the chain, retries the step or flags it for review, so a bad intermediate result never reaches the next step.
Diagram
Code controls the sequence. Gates between steps stop bad intermediate output from reaching later steps.
When to use
Use it when
- The task always breaks into the same steps
- Each step's output can be checked with code
- You need predictable cost, latency and behavior
- Different steps benefit from different prompts or models
Avoid it when
- The steps depend on what earlier results reveal; use ReAct
- The task is simple enough for one well-written prompt
- Inputs vary so much that a fixed sequence often doesn't fit
Trade-offs
Gains
- Each step can be tested, measured and improved on its own
- Predictable cost and latency per run
- Failures point to a specific step
Costs
- Rigid; unusual inputs don't fit the fixed path
- Errors that pass a gate still compound downstream
- More prompts to maintain
Worked example
A pipeline turns customer call transcripts into CRM updates for an account team.
- Step 1 · ExtractA small model pulls facts as JSON:
{competitors: ["Acme"], budget: "Q2", next_meeting: "2026-11-20", action_items: [...]}. - GateSchema check passes. A date check confirms the next meeting isn’t in the past.
- Step 2 · ClassifyLabels the deal risk from the extracted facts:
risk: medium, reason: competitor mentioned twice. - Step 3 · DraftWrites a 4-line CRM note and a follow-up email draft from steps 1–2 only, not from the raw transcript.
- GateOn a different call, the extraction returns
next_meeting: "next Tuesday". The date check fails, the chain stops, and the record is queued for a quick human fix instead of writing a bad date to CRM.
Failure modes
| Failure | Symptom | Mitigation |
|---|---|---|
| Error compounding | A small extraction error becomes a confident wrong summary | Gate each step's output; pass structured data, not prose |
| Wrong decomposition | Steps need information an earlier step discarded | Carry the original input alongside intermediate results where needed |
| Brittle to unusual inputs | Edge cases fail gates constantly | Route unusual inputs to a separate path or to ReAct |
| Prompt drift between steps | One step's format changes and breaks the next | Version step contracts; test the chain end-to-end in CI |