Prompt chaining: each step checks the last

Lesson 1 of 6 in Workflow Patterns: Five Ways to Compose Model Calls.

The previous module drew the line: in a workflow, your code decides what happens next; in an agent loop, the model does. This module is the field guide to the workflow side — five patterns that cover nearly every production system that composes LLM calls in code. Learn them by name. When a colleague says “just chain it” or “put a router in front”, these are the shapes they mean.

The first and simplest is prompt chaining: break one task into a fixed sequence of model calls, where each call consumes the previous call’s output — and, critically, where code between the steps checks that output before letting it flow downstream. One big prompt asks the model to hold five concerns at once; a chain gives each concern its own call, its own instructions, and its own gate.

Prompt chaining with a gate

  1. Input arrives
  2. Call 1: draft outline

    A focused prompt with one job. Its output is intermediate — no user ever sees it, so you can force a strict format that is easy to check.

  3. Gate: outline valid?

    Plain code, not a model: schema checks, length limits, banned-term scans, required-section checks. Deterministic, fast, free.

  4. Call 2: write full copy

    Receives only the validated outline — not the raw user input, not call 1’s reasoning. Each step gets a clean, minimal context.

  5. Call 3: translate

    Translation is its own call because it is its own skill — mixing it into the drafting prompt degrades both jobs.

  6. Deliver
  7. Retry or escalate

    A failed gate re-prompts call 1 with the validation error, or falls through to a human. It never silently passes junk forward.

The trade you are making is explicit: latency and cost stack linearly — three calls take three calls’ worth of time and tokens — in exchange for each step being simpler, more testable, and individually gateable. That trade wins whenever the task decomposes cleanly and accuracy matters more than speed.

The gates are where the engineering lives. A gate can be a schema validation on structured outputs, a regex, a unit test, or occasionally another model call — but prefer code wherever code can decide, because code is deterministic and free while a checker model reintroduces non-determinism at every gate.

Key terms: prompt chaining, quality gate, workflow, structured outputs, trace

Interactive checkpoint quiz (2 questions) — open this page in a browser to take it.