Routing & Composition

Prompt Chaining

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

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.

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.

When to use

  • 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.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related