# Prompt Chaining

> Decompose a task into a fixed sequence of LLM calls where each step's output becomes the next step's input.

- **Category**: Agentic AI
- **Subcategory**: Routing & Composition
- **Canonical URL**: https://designpattern.fyi/patterns/prompt_chaining/

---

## Description
**Intent**: Decompose a task into a fixed sequence of LLM calls where each step's output becomes the next step's input.
**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.
**Solution**: 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.


## Use Cases
- A task decomposes into a fixed sequence of LLM calls with clear handoffs.
- Each step has its own system prompt, expected output shape, and validation.
- Localised retries at a step are preferable to retrying a mega-prompt.





## Trade-offs


### Advantages

- Failures localise to a step.

- Each step's prompt can be optimised independently.




### Considerations & Drawbacks

- Inflexible to inputs that do not match the assumed decomposition.

- Latency = sum of step latencies.







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/prompt-chaining/)

