What Is Prompt Chaining? Multi-Step LLM Pipelines
Prompt chaining splits a task into a sequence of smaller LLM calls, each one feeding the next, instead of asking one giant prompt to do everything.
Prompt chaining is a technique for building LLM-powered features by breaking a task into a sequence of smaller prompts, where the output of one step becomes the input to the next. Instead of asking a single prompt to extract information, reason about it, and produce a final answer all at once, a chain splits that work into separate calls — extract, then summarize, then classify, for example — with the application code passing results from one step to the next.
Why chain instead of one big prompt
A single large prompt asking a model to do several distinct things at once tends to produce worse results on each individual sub-task than a series of focused prompts would. Models handle a narrowly scoped instruction more reliably than a compound one with several competing objectives, and it’s much easier to debug a five-step chain than a single prompt that silently skipped step three.
Chaining also gives you places to intervene. Between steps, application code can validate output, apply business logic, call an external API, or route to a different prompt entirely based on what the previous step produced. A single monolithic prompt gives you none of that — you get one shot, and either the whole thing works or it doesn’t.
A simple chain, conceptually
A common shape looks like this: a raw customer support ticket goes into step one, which extracts structured fields like the product mentioned, the sentiment, and whether it’s a bug report or a question. Step two takes that structured output and drafts a response, using a different prompt tuned specifically for reply-writing. Step three checks the drafted reply against a set of policy constraints before it ever reaches a human agent or a customer. Each step is a small, testable unit with a narrow job, and the output of one becomes the documented input contract for the next.
Reliability improves further when each step’s output is constrained to a predictable shape — see our guide to structured outputs and JSON mode for how to make a step’s output something the next step can parse without guesswork, rather than free-form prose that has to be re-interpreted.
Prompt chaining vs agents
Chaining and agentic loops both involve multiple LLM calls working toward a goal, but they differ in who decides what happens next.
| Prompt chaining | Agent loop | |
|---|---|---|
| Control flow | Fixed in advance by the developer | Decided dynamically by the model at each step |
| Predictability | High — the same steps run every time | Lower — the path can vary by input |
| Debugging | Easier — each step is a known, testable unit | Harder — the sequence of steps itself varies |
| Best for | Well-understood, repeatable workflows | Open-ended tasks where the right steps aren’t known upfront |
See what an AI agent is and the ReAct pattern for how agent loops let the model choose its own next action instead of following a hardcoded sequence. In practice, many production systems use both: a chain for the predictable parts of a workflow, with an agentic step embedded for the one part where the model genuinely needs to decide what to do next. Chain-of-thought prompting is a related but distinct idea — it’s about getting one call to reason step by step internally, while prompt chaining is about splitting the work across multiple separate calls.
Failure modes to watch for
Chains introduce their own risks that a single prompt doesn’t have:
- Error propagation. A mistake in step one — a misextracted field, a wrong classification — flows into every step after it, and the final output can look confident while being built on a bad foundation. Validating each step’s output before passing it forward catches this earlier than validating only the final result.
- Latency stacks up. Each step is a separate model call, and unless steps run in parallel where the dependency graph allows it, total latency is roughly the sum of every step’s latency. A five-step chain is meaningfully slower than one call, which matters for anything user-facing.
- Cost multiplies. Every step is a separate billed call, and if each step also resends earlier context, token costs can add up faster than a single well-crafted prompt would. Prompt caching helps when steps share a long, repeated prefix like a system prompt or a large document.
- Over-decomposition. Splitting a task into more steps than it needs adds latency and failure surface without improving reliability. If two steps always run in the same order with no branching or validation between them, they’re often better merged into one.
The takeaway
Prompt chaining trades the fragility of one large, multi-purpose prompt for a sequence of smaller, more reliable ones, with application code able to validate, branch, or call external systems between steps. It’s the right default for workflows where the sequence of operations is known ahead of time; reach for an agent loop instead when the model genuinely needs to decide what to do next rather than follow a fixed script. Most real systems end up as a mix of both — a predictable chain with an agentic step embedded wherever the task actually calls for judgment.
Tagged
Keep reading
Chisato · · 4 min read Structured Outputs: Getting Reliable JSON from LLMs
Structured outputs constrain an LLM's generation to match a schema, so responses parse reliably instead of relying on prompt instructions alone.
Chisato · · 4 min read What Is Function Calling in LLMs? Tool Use Explained
Function calling lets an LLM emit a structured request to run a specific function, turning free-form text generation into reliable tool use.
Chisato · · 4 min read Build Your Own AI Agent in 100 Lines of Python
Build a real AI agent from scratch — no framework. Just the Anthropic API, a tool-use loop, and two tools the model can call to explore your files.