Prompt Chaining
also known as Sequential Decomposition, Pipeline of Prompts
Decompose a task into a fixed sequence of LLM calls where each step's output becomes the next step's input.
This pattern helps complete certain larger patterns —
- specialisesPipes and Filters★★— Compose stream-shaped processing as a chain of small filters connected by pipes.
- specialisesChat Chain★— Decompose a long, multi-disciplinary task into ordered phases; within each phase, run a paired-role chat between two agents until the phase artefact is signed off; pass the artefact to the next phase.
Context
A team is building an agent for a task that decomposes cleanly into a fixed sequence of sub-tasks whose order is known before the request arrives — for example turning a meeting transcript into structured action items decomposes into cleaning the transcript, attributing speakers, extracting candidate actions, normalising dates and owners, and emitting validated JSON. Each sub-task has its own definition of done, its own preferred prompt, and its own shape of output. The team controls the orchestration code that runs between LLM calls.
Problem
If the team tries to do the whole task in a single mega-prompt, the model is asked to juggle several concerns at once and quality suffers across all of them. When the output is wrong, the team cannot tell which sub-task went off the rails because the steps are entangled inside one generation. Retries have to redo the entire task instead of just the failing step, and improvements to one part of the prompt risk regressing another.
Forces
- Decomposition clarity vs compounded latency.
- Step isolation vs error compounding across the chain.
- Schema rigor between steps vs pipeline flexibility.
Example
A team builds a 'turn meeting transcript into a structured action-item list' feature as one mega-prompt. Failures are hard to localise — sometimes the speaker attribution is wrong, sometimes the dates are wrong, sometimes the JSON is malformed. They split it into a prompt-chain: step one cleans the transcript and attributes speakers, step two extracts candidate action items, step three normalises dates and owners, step four validates and emits JSON. Each step has its own validator; a failure at step three retries step three instead of redoing the whole pipeline.
Diagram
Solution
Therefore:
Define a fixed pipeline of prompts. Each step has its own system prompt, expected output shape, and validation. A failure at step k retries step k or aborts; downstream steps run only on success.
What this pattern forbids. Step k cannot bypass step k-1's output schema.
The smaller patterns that complete this one —
- usesAugmented LLM★★— Build the foundational agent block as an LLM augmented with retrieval, tools, and memory that the model actively chooses to use, rather than a bare-model call.
And the patterns that stand alongside it, or against it —
- complementsRouting★★— Classify an incoming request and dispatch it to the specialist (lane / agent / model) best suited to handle it.
- alternative-toParallelization★★— Run independent LLM calls concurrently and combine results.
Neighbourhood
Click any neighbour to follow the language. Scroll to zoom, drag to pan.