Prompt chaining splits one task into connected prompts
📍 In One Sentence
Prompt chaining breaks a big task into smaller prompts and feeds the output of each step into the next, so every call has one checkable job.
💬 In Plain Terms
It works like an assembly line instead of one giant request: each station does one thing and hands its work along, so when something breaks you can see which station caused it.
Prompt chaining decomposes a task into a sequence of steps, where each LLM call processes the output of the previous one. Instead of asking for everything at once, you run steps such as analyze, plan, draft and review, each with one narrow responsibility.
Each step has a defined input, a defined output format and one job. Between steps your code can validate or edit the output, so the chain behaves like a pipeline you can test rather than a chat you hope goes well.
Chaining makes each model call easier to check
Chaining helps when a task has too many layers for one prompt to handle reliably. Separating understanding, planning, generation and checking gives you control at every stage.
- Each call is an easier task, which Anthropic describes as trading latency for higher accuracy.
- You can inspect and validate intermediate outputs, one of the two reasons Claude's prompting guide gives for chaining explicitly.
- Steps are reusable: "summarize", "extract entities" or "translate" can be shared across workflows.
- You can assign a different model to each step, for example a small fast model for extraction and a stronger one for writing.
Four common patterns for prompt chains
Most chains reuse a few recurring shapes. Pick the one that matches your task and adapt the steps.
- Analyze → Plan → Draft → Refine: articles, reports, strategies.
- Extract → Transform → Summarize: raw documents, logs, support tickets.
- Classify → Route → Generate: triage inputs, then send each to a specialized prompt.
- Draft → Review → Refine: iterative self-correction of copy, code or designs.
A three-step chain can be easier to check than one long prompt
The gain is easiest to see when one long prompt and a short chain tackle the same job. The task: turn raw release notes into a customer-facing changelog.
Single prompt
"Read these release notes and write a friendly changelog for our users."
Prompt chain
Step 1, extract: "Extract all user-visible changes from the raw release notes and list them as bullets grouped by feature area."
Step 2, classify: "Label each bullet as bug fix, improvement or new feature, and add a one-line note on why it matters."
Step 3, write: "Using the labeled list, write a short changelog email with an intro and 3–6 bullets. Focus on benefits, not internal details."
Each prompt is now simpler, testable on its own and reusable in other workflows.
Prompt chaining examples for common tasks
These examples show where a chain replaces one overloaded prompt. The first two come from Anthropic's description of the pattern; the review chain is the self-correction pattern from Claude's prompting guide.
Use case | Chain steps | Why chain it |
|---|---|---|
| Marketing copy | Write copy → translate | Check the copy before translating |
| Document writing | Outline → check → write | Gate the outline before drafting |
| Support triage | Classify → route → reply | Each category gets its own prompt |
| Code or text review | Draft → review → refine | Separate calls for writing and critique |
| Log analysis | Extract → group → summarize | Keeps each call small and checkable |
LangChain prompt chaining example in Python
To chain prompts in LangChain, load a chat model with `init_chat_model`, call `invoke` once per step and pass each step's text into the next prompt. The sample runs the changelog chain from above; it assumes `langchain`, your provider's integration package and its API key are set up.
For advanced needs, LangChain points to LangGraph, its low-level orchestration framework for combining deterministic and agentic workflows (for example branching or loops). Agents are created with `create_agent`.
from langchain.chat_models import init_chat_model
model = init_chat_model("claude-sonnet-4-6") # any supported chat model
def run(prompt: str) -> str:
return model.invoke(prompt).text
notes = "..." # raw release notes
changes = run(f"List every user-visible change as bullets:\n{notes}")
labeled = run(f"Label each bullet as bug fix, improvement or new feature:\n{changes}")
email = run(f"Write a short user-facing changelog email from this list:\n{labeled}")
print(email)Use a chain for fixed stages and a single prompt for small tasks
Use prompt chaining when a task splits into fixed stages that can fail or change independently. A very long prompt full of "if" conditions is usually a sign it needs a chain.
- Use a chain: content pipelines (research → outline → draft → edit), data pipelines (ingest → clean → extract → summarize), decision support (facts → options → trade-offs → recommendation).
- Use a single prompt: small one-off tasks where you do not need to inspect intermediate results.
- Consider an agent instead: open-ended problems where the steps cannot be fixed in advance (Anthropic separates fixed workflows from agents).
Prompt chain vs single prompt vs chain-of-thought
The three approaches differ in where the work happens. A chain splits it across calls; chain-of-thought keeps it inside one answer.
Dimension | Single prompt | Prompt chain | Chain-of-thought |
|---|---|---|---|
| Model calls | One | One per step | One |
| Where reasoning happens | Inside one answer | Across steps, in your code | Written out in one answer |
| Inspect mid-way | No | Yes, after every step | Only by reading the text |
| Cost and latency | Lowest | Higher: one call per step | Slightly higher: longer output |
| Best for | Simple tasks | Tasks with fixed stages | Logic-heavy single questions |
Frameworks automate chains but the idea stays the same
You can chain by hand with plain API calls, or use a framework for orchestration. The concept is identical; frameworks add tracing, retries and structure.
- LangChain: `init_chat_model` for models, `create_agent` for agents, LangGraph for low-level orchestration.
- DSPy (Khattab et al.): compiles declarative language-model calls into pipelines that improve themselves.
- Anthropic, Building effective agents: prompt chaining and other workflow patterns, with advice on when to use each.
- Claude prompting guide, "Chain complex prompts": explicit chaining "is still useful when you need to inspect intermediate outputs or enforce a specific pipeline structure".
How to build a prompt chain in five steps
- 1Split the task into stages with one job each. For a blog post: outline, draft sections, fact-check, format.
- 2Define the output format of every step. If step 2 expects JSON, tell step 1 to produce exactly that JSON.
- 3Test each step alone before linking them. Run step 1 on ten real inputs and fix it before you build step 2.
- 4Add checks between steps. A programmatic gate or a human review after costly steps stops errors from cascading.
- 5Log intermediate outputs and iterate. When the result is wrong, the logs show which step to fix.
Four prompt chaining mistakes to avoid
❌ Too many steps
Why it hurts: Every step adds latency and another chance for the model to err.
Fix: Start with the fewest steps that make each call simple; merge steps that do not change the result.
❌ Vague handoff format
Why it hurts: Step 2 cannot rely on "a list of ideas" from step 1.
Fix: Specify the exact format, such as JSON keys, and show an example output.
❌ No checks between steps
Why it hurts: A bad outline becomes a bad draft and a worse final text.
Fix: Validate or review the output of the steps where an error would be costly.
❌ Testing only the full chain
Why it hurts: When the final output is wrong you do not know which step failed.
Fix: Test each step in isolation first, then test the chain end to end.
Errors compound across steps
Every step is another point where the model can be wrong. As illustrative arithmetic, not a measurement: if five steps are each right 95% of the time and errors are independent, the whole chain is right about 77% of the time (0.95 to the power of 5).
That is why short chains, per-step tests and checks between steps matter more than adding stages.
Compare models on a single chain step in PromptQuorum
PromptQuorum sends one prompt to several models and shows the answers side by side. For a chain, run one step across models to see which handles it best before you commit that step to a model.
Frequently Asked Questions
What is prompt chaining?
Prompt chaining is a technique that decomposes a task into a sequence of steps, where each LLM call processes the output of the previous one. Each step has one narrow job, and you can check or edit the result between steps.
What does prompt chaining consist of?
It consists of splitting a large task into smaller, connected prompts. The first prompt produces an output in an agreed format, that output becomes part of the second prompt, and so on until the final step produces the result you need.
What is the difference between prompt chaining and chain-of-thought prompting?
Chain-of-thought asks the model to write out its reasoning inside one prompt and one answer. Prompt chaining uses several separate calls, with your code passing results between them. You can combine both: use chain-of-thought inside a step of a chain.
How do you do prompt chaining in LangChain?
Load a model with `init_chat_model`, call `invoke` for the first prompt, read the text of the response and insert it into the second prompt, and repeat. For advanced needs, LangChain points to LangGraph, its low-level orchestration framework for combining deterministic and agentic workflows (for example branching or loops).
When should you not use prompt chaining?
Skip it for small one-off tasks where one prompt works, and when you do not need to inspect intermediate results. For open-ended problems where the steps cannot be fixed in advance, Anthropic suggests an agent rather than a fixed workflow.
How many steps should a prompt chain have?
There is no fixed number. Use the fewest steps that make each call simple, because every step adds latency, cost and another chance for an error. Merge any step whose removal does not change the output.
Is prompt chaining the same as fine-tuning?
No. Chaining changes how you call a model, using several prompts in sequence. Fine-tuning changes the model itself by training it on examples. They can be combined, and the comparison of prompt engineering and fine-tuning explains when each fits.
What is a simple example of prompt chaining?
Anthropic's example: generate marketing copy in one call, then translate it into another language in a second call. Between the two calls you can check the copy before it is translated.
Sources and Further Reading
- Anthropic, "Building effective agents" — definition of prompt chaining, when to use it and examples.
- Claude prompting guide, "Chain complex prompts" — when explicit chaining is still useful and the draft, review, refine pattern.
- Wu, Terry and Cai (2022). "AI Chains: Transparent and Controllable Human-AI Interaction by Chaining Large Language Model Prompts." CHI 2022. arXiv:2110.01691 — user study with 20 participants on chaining.
- LangChain documentation — `init_chat_model`, `create_agent` and LangGraph.
- Khattab et al. (2023). "DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines." arXiv:2310.03714 — programmatic prompt pipelines.
