Agentic Pattern Libraryby Vikas Goyal
← All patterns
05

Prompt Chaining

Also known as: pipeline, sequential workflow, LLM chain

A fixed sequence of LLM calls with checks between steps. Predictable and debuggable.

TrackAgentic systems FamilyCore loop Maturity Established ChangesDecision
01

Problem

One large prompt that asks a model to extract, analyze, decide and write all at once is hard to get right and harder to debug. When the output is wrong, you can’t tell which part of the job failed, and small prompt changes have unpredictable effects.

  • Smaller, focused prompts are more accurate than one prompt doing everything.
  • Each extra call adds latency and a place for errors to compound.
  • Fixed steps are predictable but can’t adapt to unusual inputs.
  • Teams need to test and improve each part independently.
02

Solution

Break the task into a fixed sequence of steps, each a separate LLM call with one job and a defined output format. Code, not the model, decides the order. Between steps, add gates: cheap programmatic checks such as schema validation, required fields or length limits. A failed gate stops the chain, retries the step or flags it for review, so a bad intermediate result never reaches the next step.

03

Diagram

Input 1 · Extractfacts as JSON Gateschema 2 · Classifylabel + reason 3 · Draftnote + email Out Stop & flagretry or human fix check fails code decides the order · each step has one job and a fixed output format

Code controls the sequence. Gates between steps stop bad intermediate output from reaching later steps.

04

When to use

Use it when

  • The task always breaks into the same steps
  • Each step's output can be checked with code
  • You need predictable cost, latency and behavior
  • Different steps benefit from different prompts or models

Avoid it when

  • The steps depend on what earlier results reveal; use ReAct
  • The task is simple enough for one well-written prompt
  • Inputs vary so much that a fixed sequence often doesn't fit
05

Trade-offs

Latency Steps run in sequence; total grows with length
Cost Predictable; small models can handle simple steps
Complexity Plain code orchestration, no agent loop
Reliability Each step is testable; gates catch drift

Gains

  • Each step can be tested, measured and improved on its own
  • Predictable cost and latency per run
  • Failures point to a specific step

Costs

  • Rigid; unusual inputs don't fit the fixed path
  • Errors that pass a gate still compound downstream
  • More prompts to maintain
06

Worked example

Scenario
A pipeline turns customer call transcripts into CRM updates for an account team.
  1. Step 1 · ExtractA small model pulls facts as JSON: {competitors: ["Acme"], budget: "Q2", next_meeting: "2026-11-20", action_items: [...]}.
  2. GateSchema check passes. A date check confirms the next meeting isn’t in the past.
  3. Step 2 · ClassifyLabels the deal risk from the extracted facts: risk: medium, reason: competitor mentioned twice.
  4. Step 3 · DraftWrites a 4-line CRM note and a follow-up email draft from steps 1–2 only, not from the raw transcript.
  5. GateOn a different call, the extraction returns next_meeting: "next Tuesday". The date check fails, the chain stops, and the record is queued for a quick human fix instead of writing a bad date to CRM.
07

Failure modes

FailureSymptomMitigation
Error compoundingA small extraction error becomes a confident wrong summaryGate each step's output; pass structured data, not prose
Wrong decompositionSteps need information an earlier step discardedCarry the original input alongside intermediate results where needed
Brittle to unusual inputsEdge cases fail gates constantlyRoute unusual inputs to a separate path or to ReAct
Prompt drift between stepsOne step's format changes and breaks the nextVersion step contracts; test the chain end-to-end in CI