esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

What Is Prompt Chaining?

What prompt chaining is, why splitting a task into steps helps, where code checks go between them, and when one prompt is enough, for your AI interview.

In short

Prompt chaining splits one big task into a fixed sequence of model calls, where each step takes the previous step's output. Plain code checks between the steps catch errors early, so each call stays small and easy to test.

10 min readBeginnerCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Prompt chaining means breaking one big task into a fixed sequence of smaller model calls. Each step takes the last step's output as its input. I put plain code checks between the steps, so a bad result stops the chain before it reaches a customer. It costs more calls and more waiting, so I only chain when the steps are clear and the checks matter.

What is prompt chaining, in plain words?

Some tasks are too big for one prompt to do well. Prompt chaining cuts the task into a row of smaller model calls, and the output of each call becomes the input for the next one.

Think of a claims handler at an insurer. First they read the form, then they check the policy, then they write the letter. Each stage passes the file on. A chain does the same job with model calls, with plain code checks in between.

Here is a real AI case. A claims team gets an email from a policyholder about a stolen laptop. One model call pulls out the policy number and the amount. A code check confirms the policy exists. Only then a second model call drafts the reply.

Key words

Prompt chain
A fixed series of model calls, where each call takes the last call's output.
Step
One model call with one small job, such as pulling out fields.
Gate
A plain code check between two steps. It can stop the chain.
Workflow
A system where your code decides the path, not the model.

How does a chain work, step by step?

  1. 1

    Split the task

    Cut the job into fixed subtasks that always run in the same order.

  2. 2

    Give each call one job

    Each model call gets a short, narrow prompt and the output of the step before.

  3. 3

    Check between steps

    Plain code checks the output. A failed check stops the chain, so a bad result never reaches the next step.

  4. 4

    Ship the last result

    Only the final output goes out. A person reviews it first when money or a customer is involved.

A claims reply, as a chain with a gate

Claim email

from a policyholder, not yet checked

Pull out the facts

model: one small job

Check the facts

code: policy real, amount under limit?

Draft the reply

model: uses checked fields only

Chain stopped

a person picks it up

Sent after review

a person reads it first

  1. 1The email goes to the first model call.
  2. 2The model hands back fields, such as a policy number and an amount.
  3. 3If the policy exists and the amount is within its limit, the chain goes on.
  4. 4If a check fails, the chain stops and nothing is drafted.
  5. 5A person reads the draft before anything is sent.
Two model steps with a code gate between them. The claim email goes to the model, which pulls out the facts. Code checks the policy: a pass drafts the reply, a fail stops the chain. A person reads the draft before it is sent.

Why split the task, and what does it cost?

  • Gain

    Accuracy

    Each step is an easier task, and you can check it on its own.

  • Cost

    Time and calls

    More calls mean more waiting and more bills. An early mistake flows down the chain.

  • Gain

    Control

    Each step is a separate call you can log, and you can branch or stop at any point.

  • “Prompt chaining decomposes a task into a sequence of steps, where each LLM call processes the output of the previous one.”

    Anthropic, Building effective agents

  • “The main goal is to trade off latency for higher accuracy, by making each LLM call an easier task.”

    Anthropic, Building effective agents

  • “Explicit prompt chaining (breaking a task into sequential API calls) is still useful when you need to inspect intermediate outputs or enforce a specific pipeline structure.”

    Anthropic, prompting guide

  • “we introduce the concept of Chaining LLM steps together, where the output of one step becomes the input for the next, thus aggregating the gains per step”

    Wu and colleagues, AI Chains paper (2021)

A 2021 paper introduced chaining LLM steps. It ran a 20-person user study, and its authors found that chaining improved task quality and made the system more transparent and easier to control.

Should you always chain prompts?

No. A single call is often enough, and each extra step is more to build, test and pay for. Anthropic's guide says to find the simplest solution possible, and to add complexity only when it helps.

One big prompt, or a chain?

One big prompt

One call does all

reads, checks and writes at once

A chain

Step 1: extract

one small job

Step 2: gate

code check, can stop

Step 3: draft

model writes from checked facts

Hard to debug

no idea which part failed

Each step tested

a failing step shows up alone

  1. 1One call reads, checks and writes, so a failure is hard to pin down.
  2. 2The first small job hands back fields a program can read.
  3. 3The gate checks those fields before the model drafts anything.
  4. 4Each step can be tested alone, and the last step gives the final result.
Two ways to do the same claims job. One big prompt is quick to write but hard to check when it fails. A chain costs more calls, but each step can be tested alone and the gate stops bad results early.

Anthropic's own docs say that, with adaptive thinking and subagent orchestration, Claude handles most multistep reasoning internally. So explicit chains matter less for reasoning, and more when you need to see the middle results or force a fixed order.

How would you build a claims reply chain?

Here is a small version with fake model calls. Each one returns a fixed answer, so you can run it and see what the gate does.

Python
# A simplified claims chain. The model calls are stubbed, so the output below is always the same.
POLICY_LIMITS = {"POL-4471": 2500, "POL-9020": 800}

def step1_extract(email_id):
    # Step 1, the model: read the email and return fields. Stubbed: email-102 has a swapped digit.
    fake_model = {
        "email-101": {"policy": "POL-4471", "amount": 1800},
        "email-102": {"policy": "POL-4417", "amount": 600},
    }
    return fake_model[email_id]

def step2_gate(fields):
    # Code, not the model, checks the fields before the next step runs.
    if fields["policy"] not in POLICY_LIMITS:
        return "STOP: policy " + fields["policy"] + " does not exist"
    if fields["amount"] > POLICY_LIMITS[fields["policy"]]:
        return "STOP: claim is over the policy limit"
    return "PASS"

def step3_draft(fields):
    # Step 3, the model: write a reply from the checked fields only. Stubbed here.
    return "We received your claim for " + str(fields["amount"]) + " on " + fields["policy"] + "."

for email_id in ["email-101", "email-102"]:
    fields = step1_extract(email_id)
    verdict = step2_gate(fields)
    print(email_id, verdict)
    if verdict == "PASS":
        print(step3_draft(fields))

Output

email-101 PASS
We received your claim for 1800 on POL-4471.
email-102 STOP: policy POL-4417 does not exist

Take two claim emails, both quoting policy POL-4471. For the first, the model reads the number right. For the second, it swaps two digits and reads POL-4417. The gate catches that before any reply is drafted. A good claim needs two model calls. A stopped one needs one.

Tip

Asked how you'd build it? Name the three steps, the gate, and what happens to a stopped claim: a person picks it up, and nothing reaches the customer unchecked.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: a fixed series of model calls, each taking the last one's output.
  • Why it helps: each step is smaller, so it is easier to get right and to test.
  • Gates: plain code checks between steps, so a bad result stops early.
  • The cost: more calls, more waiting, and an early error spreads to later steps.
  • When not to: one call is often enough. With adaptive thinking and subagent orchestration, Claude handles most multistep reasoning internally.
  • The fit test: the task splits into fixed subtasks you can check.

Common traps

  • Trap"Chaining is just chain-of-thought."

    BetterChain-of-thought is reasoning inside one call. Chaining runs several calls, with a check between them.

  • Trap"Put every step in one longer prompt."

    BetterOne prompt is harder to test. A chain shows you which step broke.

  • Trap"More steps always gives a better answer."

    BetterEach step adds delay and cost, and an early error spreads to later steps. Add a step only when it fixes a measured problem.

Can you spot a real chain?

Spot the chain

Which of these is a prompt chain, not just one prompt?

Quick check

A claims team wants every reply checked before a customer sees it. Which design fits prompt chaining best?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q078What is chain-of-thought, and when does it help?10 min
  2. Q091What is ReAct prompting?11 min
  3. Q085How do you get reliable JSON output?12 min
  4. Q087Why template and version your prompts?11 min
  5. Q096What is compaction (summarising history)?11 min
  6. Q100How do you test prompts systematically?12 min

Last updated on 26 November 2026

Building a multi-step AI workflow for real work?

I design and build AI agents and the workflows behind them, including the checks between steps. Book a short call and tell me what your process needs to do.