Prompt Chaining

Descomposición · Un trabajo por llamada

Escrito por Darjus Kazakevic · revisado el

One job per call.

One prompt that extracts facts, classifies them and drafts a reply is doing three jobs. When the draft is wrong, you cannot tell which job failed. Splitting it into three calls gives each step its own instructions and examples. It also gives you a result to check before the next step uses it.

The cost is real: more calls, more latency, more code, and errors that add up along the chain. Pay it when the steps are different tasks, need different models, or need a check between them. Do not split one clear job into steps just for neatness.

En esencia — When a prompt does three things badly, the fix is usually three prompts with a check between them, not more instructions.

Cuándo recurrir a él

Recurre a él cuando

  • One prompt does several jobs and you cannot tell which one fails
  • A step needs a different model, temperature or tool set
  • You need a check between steps: validation, a human, an early exit

Reconsidéralo cuando

  • The task is one job, so splitting adds only latency
  • A tight latency budget, and steps that must run one after another
  • The next step depends on a choice only the model can make: that is an agent

The parts

The step
One call with one job and a result the next step can use. Each step gets its own instructions and examples. Most of the gain comes from here: a focused prompt is a better prompt.
The seam
The typed result passed between two steps, and the place where you can look. At a seam you validate, filter, retry one step or stop early. A single prompt allows none of this.
The chain
The fixed sequence, decided by your code, not by the model. That is the line between a chain and an agent: here the control flow is written down and reviewable.

Reglas de diseño

Check the result at every seam
Validate each step's output before the next step uses it. Knowing which step broke is the main reason to chain, and you paid for it in latency. Do not let a bad result flow on.
Split on jobs, not on length
A long prompt doing one thing is fine. A short prompt doing three is the one to split. Test: can you name each step's output without mentioning the others?
Pass typed data between steps
One step's output is the next step's input, so give it an output contract. Prose passed between calls is where a chain silently loses a field.
Keep the control flow in your code
When the model chooses the next step, you have an agent. It then needs a stop condition, a turn budget and a saved transcript. Build that on purpose, not by accident.

Errores habituales

  • Passing prose between steps instead of typed data
  • No check at the seams, so one bad early result spoils the rest
  • Adding branches until the chain is an agent loop nobody designed