AI Agentic Handbook
Agents

Prompt chaining

Budding levelReviewed Oct 2026In 4 interview questionsIn 1 post

A fixed sequence of model calls, each feeding the next, with your own checks between the steps.

In plain English

Prompt chaining splits a big task into small steps, each its own call to an Large Language Model (LLM), each output feeding the next. Step 1 pulls the facts out of a document, step 2 drafts from those facts, step 3 checks the draft.

A programmer writes the steps in advance, which makes it a workflow rather than an AI agent (see Workflow vs agent). Small focused steps are easier for the model to get right and easier for you to test one at a time.

Analogy

An assembly line with an inspector between stations: each station does one job, and a bad part is pulled before it reaches the next.

Common pitfall

Passing free-form text between the links with no validation is the quick way to build it. One malformed output then corrupts every later step, quietly — type the handoffs and put a gate on each one.

How it actually works

Each link has a narrow Prompt & system prompt, its own model (small and fast for extraction, stronger for synthesis) and a typed output via Structured output / decoding, so the next link receives valid input. Gates between links — schema validation, a length or citation check, a classifier — stop errors early instead of letting them compound. Anthropic's "Building effective agents" lists this as the first workflow pattern: trade latency for accuracy by making each call easier.

Errors multiply: four links at 97% each give 0.97⁴ ≈ 88.5% end to end if failures are independent, which is why gates and per-link evals matter. Latency is the sum of sequential links unless independent links run in parallel. Because each link is evaluable alone, a regression can be pinned to one link in an Eval harness. It is the default skeleton for tasks with a known decomposition and the frame into which an agentic step is inserted when one branch needs it.

What I'd ship on day one

3–5 links; JSON Schema output on every link that feeds code; deterministic gates (schema, citation present, length) before any LLM-based gate; cheapest model that passes each link's golden set; failed gate → one retry with the error message, then route to a fallback or human queue.

Worked example

Developer-docs release notes: (1) small model extracts changed APIs from 30 merged PRs as JSON (1.1 s); (2) gate: every item must cite a PR number, else drop and log; (3) larger model drafts notes from the JSON (2.4 s); (4) gate: banned-claims and broken-link check. End to end 3.9 s, ≈ $0.02 per release. When notes went wrong, logs showed link 1 had mislabelled a deprecation — fixed in that prompt alone.

In the interview

Offer it as the simplest design that works whenever the decomposition is already known, and say exactly where the gates sit between links. Recommend a golden set per link, so a regression tells you which link broke rather than that something, somewhere, got worse.

Expect 'latency is too high' — parallelise independent links, use smaller models on the easy ones, or merge two links whose gate never actually fires.

01Extractsmall model, JSON
02Gateschema + citations
03Draftlarger model
04Gatepolicy check
05Output
Fixed steps, typed handoffs, a check between each.

Numbers worth knowing

End-to-end accuracy
Π link accuraciesindependent errors: 0.97⁴ ≈ 88.5%, 0.99⁴ ≈ 96%
Latency
Σ sequential linksparallel links count once (the slowest)

How to decide

WhenDo this
The task splits into steps that are the same for every inputChain them with a gate after each step.
Two links are independentRun them in parallel (Anthropic's sectioning pattern).
A gate fails often on one linkFix that link's prompt or model; don't add retries downstream.

Cost maths

Cost = Σ links (in_i × p_in,i + out_i × p_out,i). Release-notes example (illustrative, Oct 2026): link 1 on a $1 / $5 model with 9k in / 600 out = $0.012; link 3 on a $3 / $15 model with 1.5k in / 500 out = $0.012; gates are code (≈ $0). ≈ $0.024 per release. A single big prompt on the $3 model costs ≈ $0.035 and fails more often because one call does both jobs.

Operating it

Time to scale up when…
  • A gate fails on >5% of inputs
  • End-to-end latency exceeds the SLO while links sit idle (parallelise)
  • One link needs input-dependent branching (add routing or an agentic step)
What to monitor
  • Gate failure rate per link (alert > 5%)
  • Per-link golden-set pass rate (alert on −3 points)
  • End-to-end p95 latency (alert above SLO)

When it goes wrong

What users saw

Product descriptions in an e-commerce catalog began citing dimensions from the wrong SKU.

How it was caught

Merchant reports, confirmed by a sample audit showing 3% of descriptions mismatched their spec sheets.

Root cause

Link 1 returned free text; when the spec sheet had two tables, link 2 parsed the second one. No gate checked that the extracted SKU matched the input SKU.

Fix

Link 1 emits JSON with sku and source_row; a gate rejects any mismatch; mismatches dropped to 0 and 0.4% of items route to manual review.

Sources

  1. Building effective agents — Anthropic (Schluntz & Zhang), 2024blog
  2. Chain of Thought Prompting Elicits Reasoning in Large Language Models — Wei et al., 2022paper

Check yourself

Three questions. Every option is explained once you answer.

1ConceptWhat is the main purpose of a gate between two links in a prompt chain?
2ScenarioCatalog descriptions started citing dimensions from the wrong SKU. Link 1 returns free text that link 2 parses. Best fix?
3CalculationLinks take 1.1 s, 0.01 s (gate), 2.4 s and 0.01 s (gate), all sequential. If link 1 and a 1.0 s independent link ran in parallel, what's the new total?