Prompt Chaining
Break a task into fixed steps, each a focused model call whose output feeds the next, with ordinary code checking results in between.
Description
One giant prompt that must extract, reason, write and format all at once is hard to get right and hard to debug. Prompt chaining splits the job into a predefined sequence of smaller calls: extract the facts, then draft, then translate, each with its own short, testable prompt.
Between steps, normal code can validate the output (is it valid JSON, are the required fields present?) and stop or retry early. The path is decided by you, not the model, which makes chains predictable, cheaper to run and easy to evaluate step by step.
System design
Prompt Chaining system design diagram
- Support ticket (client).
- 1 · Extract facts (language model): → JSON.
- Validate (function): plain code.
- 2 · Draft reply (language model).
- 3 · Translate (language model): customer's language.
- Step 1: Support ticket → 1 · Extract facts: ticket text.
- Step 2: 1 · Extract facts → Validate: { product, issue, tone }.
- Step 3: Validate → 2 · Draft reply: valid facts only.
- Step 4: 2 · Draft reply → 3 · Translate: English draft.
- A support ticket comes in.
- The first model call extracts structured facts (product, issue, tone) as JSON, and nothing else.
- Ordinary code checks the JSON. If fields are missing, it retries or routes the ticket to a person instead of continuing.
- The second call drafts a reply from the validated facts. Then a third call translates it into the customer's language. Each step has its own short prompt and test cases.
- AWS
- Step Functions calling Amazon Bedrock; Bedrock Prompt Flows.
- Azure
- Azure AI Foundry prompt flow; Durable Functions with Azure OpenAI.
- Google Cloud
- Workflows calling Vertex AI; Vertex AI Agent Builder playbooks.
When to use it
Use it when
- The task decomposes cleanly into steps that are always the same.
- You want higher reliability, and are willing to trade some latency for it.
- Intermediate results should be checked, logged or reviewed by a person.
Avoid it when
- The steps depend on what's discovered along the way. That's an agent.
- A single well-written prompt already does the job reliably.
- Latency is critical and every extra call hurts.
Pitfalls
- Errors compounding: a small mistake in step 1 grows by step 4. Validate between steps.
- Passing huge outputs along the chain. Pass only what the next step needs.
- Evaluating only the final output. Keep test cases per step to find which one regressed.
Alternatives
AI Agent
Choose it when the model needs to decide the steps itself based on what it finds.
Evaluator–Optimizer
Choose it when quality improves by critiquing and revising, not by splitting into steps.
Single prompt
Choose it when the task is simple enough that one call is reliable.