Chaining Focused Prompts for Complex Tasks
This lesson describes common prompt chaining patterns and where to implement them, since complex tasks are more reliable as a chain of small, focused prompts than as one large prompt.
Learning outcomes
After completing this lesson, you will be able to:
- Build sequential chains.
- Use branching, parallel and iterative chains.
- Choose where to implement a chain.
Sequential chains
A single prompt that asks a model to extract facts, analyse them and write a polished report at once often does each part poorly, and when the result is wrong it is hard to tell which part failed. Prompt chaining divides the work. In a sequential chain, the output of one prompt becomes the input of the next: extract facts from a document, then analyse them, then write a summary for a specific audience.
Each step has its own instructions, examples, model and parameters, so a small, cheap model can handle extraction while a larger model writes the analysis. Each step can also be tested and improved separately. Validation between steps, such as checking that extracted JSON is valid and complete, stops an error in an early step from propagating silently into the final result.
Why chain prompts?
Branching, parallel and iterative chains
Chains are not always a straight line. In conditional branching, one prompt's output, such as a classification, determines which prompt runs next; a support request classified as a billing question, for example, goes to a prompt with billing rules and examples. Parallel chains run independent prompts at the same time, such as analysing each section of a contract separately, and merge the results, which reduces total latency.
Map-reduce handles documents longer than the context window: each chunk is summarised separately, and the summaries are then summarised together. Evaluator-optimizer loops improve quality iteratively: one prompt generates a draft, another critiques it against defined criteria, and the draft is revised until the critique passes or a maximum number of iterations is reached. The iteration limit is essential, because without it a loop that never satisfies the critic would run, and cost money, indefinitely.
The following diagram shows a map-reduce chain that summarises a 300-page report.

Chain patterns
Where to implement chains
Chains can be implemented in three places, each suited to different needs. Amazon Bedrock Flows implement chains declaratively, as connected nodes, with versioning and no orchestration code, which suits prompt-centric chains that business users may also adjust. AWS Step Functions implements chains with Bedrock service integrations, Parallel and Map states, retries, error handling and waits of up to a year, which suits production workflows that also call other AWS services or need human approval.
Application code, or an agent framework, implements chains when they are embedded in an application and need custom logic between steps. Whichever is used, prompts from Prompt Management can be shared across all three, so that the same approved prompt is used wherever a step appears. The following table summarises the chaining patterns.
| Pattern | Use for | Typical implementation |
|---|---|---|
| Sequential | Extract, analyse, write | Flows or Step Functions sequence |
| Conditional branching | Different handling per category | Flows condition node; Step Functions Choice |
| Parallel / map-reduce | Independent parts; long documents | Step Functions Parallel or Map; Flows iterator |
| Evaluator-optimizer | Quality-critical drafts | Step Functions loop with iteration limit |
Summarising 300-page reports
A firm must summarise 300-page reports that exceed the model's context window, highlighting risks, within a few minutes.
A single prompt cannot hold the report. A map-reduce chain in Step Functions splits the report into sections, summarises them in parallel with a Map state, extracts risks from each section summary, and then combines the section summaries and risks in a final prompt. Parallelism keeps the total time within minutes.
What stops an evaluator-optimizer loop from running indefinitely?
Show answer
An iteration limit, after which the best result so far is returned or the task is escalated.
Exam Tips
Remember for the exam
- Split complex tasks into focused prompts and validate between steps.
- Long documents beyond the context window: map-reduce chains.
- Quality-critical output: evaluator-optimizer loop with an iteration limit.
- Declarative chains: Flows; chains with AWS integrations and waits: Step Functions.