All articles
December 14, 2024 4 min read

Prompt Chaining: the workflow pattern to reach for first

The simplest AI workflow pattern — decompose a task into a fixed sequence of LLM calls, each handling one job, with gates to catch failures before they compound.

Written forEngineering
AI WorkflowsDesign PatternsPrompt Chaining

Most teams try to make one giant prompt do everything — extract, reason, format, and validate in a single call. It works in the demo and falls apart in production. Prompt chaining is the fix, and it's the first pattern I reach for: break the task into a fixed sequence of steps, where each LLM call handles one narrow job and feeds the next.

InLLM Call 1Pass?Fail → stopnoyesLLM Call 2LLM Call 3Out
Each call does one job; a gate between steps rejects bad intermediate output before it propagates.

How it works

You trade one hard call for several easy ones. Each step has a single responsibility and a much smaller surface area to get wrong. Between steps you can add a programmatic gate — a schema check, a length test, a classifier — that stops the chain early instead of letting a bad draft sail through to the customer.

  • Each step is simpler, so accuracy per step goes up.
  • Gates catch failures at the cheapest possible moment.
  • You can evaluate and debug one link at a time, not a black box.
The shape of a chain
const outline = await llm(outlinePrompt, input);
if (!passesGate(outline)) return fallback();   // fail fast

const draft  = await llm(draftPrompt, outline);
const final  = await llm(polishPrompt, draft);
return final;

When to use it

Reach for prompt chaining whenever a task decomposes cleanly into fixed, ordered subtasks — generate then translate, outline then write, extract then summarise. The steps are known in advance; you're trading a little latency for a large gain in reliability.

One prompt doing five jobs is a demo. Five prompts doing one job each is a product.
Building something with LLMs?
I help teams ship GenAI that’s reliable and cost-efficient.
Let’s talk