# 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.

AI and LLM interview question Q092, Prompt and context engineering. Beginner, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-prompt-chaining

## Say it in 30 seconds

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.

## Say it in 2 minutes

Prompt chaining is a simple pattern. You take a task that is too big for one prompt and cut it into steps. The first call does one small job, such as pulling the facts out of a claim email. Its output becomes the input for the next call, which does the next job. Anthropic's guide to building agents calls this a workflow: a fixed path that your code controls.

The reason is accuracy. A model doing one narrow job makes fewer mistakes than one that reads, checks and writes in the same breath. The trade-off is time and money, because every step is another call. That is why I add code checks between steps. If the first step invents a policy number, a plain lookup stops the chain before a reply goes out.

Each step can be logged, tested on its own and swapped out. When a reply goes wrong, I can see which step broke and fix that one. I don't chain simple jobs, though. Anthropic's current prompting guide says that, with adaptive thinking and subagent orchestration, Claude handles most multistep reasoning internally. So I chain only where I need to inspect the middle results or force an order.

In an interview, I'd name three things: the fixed steps, the checks in code between them, and the cost in time and calls. I'd also say that more steps don't guarantee a better answer.

## 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.

- **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. **Split the task:** Cut the job into fixed subtasks that always run in the same order.
2. **Give each call one job:** Each model call gets a short, narrow prompt and the output of the step before.
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. **Ship the last result:** Only the final output goes out. A person reviews it first when money or a customer is involved.

*Diagram, A claims reply, as a chain with a gate: 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.*
1. The email goes to the first model call.
2. The model hands back fields, such as a policy number and an amount.
3. If the policy exists and the amount is within its limit, the chain goes on.
4. If a check fails, the chain stops and nothing is drafted.
5. A person reads the draft before anything 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.

*Diagram, One big prompt, or a chain?: 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.*
1. One call reads, checks and writes, so a failure is hard to pin down.
2. The first small job hands back fields a program can read.
3. The gate checks those fields before the model drafts anything.
4. Each step can be tested alone, and the last step gives the final result.

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:

```text
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." Better: Chain-of-thought is reasoning inside one call. Chaining runs several calls, with a check between them.
- Trap: "Put every step in one longer prompt." Better: One prompt is harder to test. A chain shows you which step broke.
- Trap: "More steps always gives a better answer." Better: Each 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?

A. Summarise this 40-page policy in one paragraph.
B. Read the claim, then pull out the policy number. Check it exists in code. Draft the reply from the checked fields.
C. Think step by step and show your working before you answer.
D. Use the best model for every claim in the queue.

**Answer:** B. Three model jobs run in a fixed order, and code checks sit between them. Thinking step by step happens inside one call, so it is not a chain.

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

A. One long prompt that does everything, then send
B. Three steps with a code check between them, and a person before sending
C. A bigger model with longer standing instructions
D. A lower temperature, which makes the output less random

**Answer:** B. The chain breaks the job into checkable steps, the code gate stops bad fields, and a person signs off. A bigger model or longer instructions do not add a check.

## Can you answer these from memory?

**Flash cards**

- **What is prompt chaining?** A fixed series of model calls, where each call takes the last call's output.
- **What is a gate?** A plain code check between two steps. It can stop the chain.
- **What does a chain cost?** More calls, more waiting. Each step adds delay and a bill.
- **Chaining vs chain-of-thought?** Chaining runs several calls. Chain-of-thought reasons inside one call.
- **When is a chain worth it?** When the task splits into fixed subtasks and each step needs checking.
- **Is one prompt enough?** Often, yes. Add steps only where they fix a measured problem.

## Likely follow-up questions

- Q078 What is chain-of-thought, and when does it help? https://designervenkat.online/interview/ai/what-is-chain-of-thought-prompting
- Q091 What is ReAct prompting? https://designervenkat.online/interview/ai/what-is-react-prompting
- Q085 How do you get reliable JSON output? https://designervenkat.online/interview/ai/how-to-get-reliable-json-from-an-llm
- Q087 Why template and version your prompts? https://designervenkat.online/interview/ai/why-template-and-version-your-prompts
- Q096 What is compaction (summarising history)? https://designervenkat.online/interview/ai/what-is-compaction-summarising-history
- Q100 How do you test prompts systematically? https://designervenkat.online/interview/ai/how-to-test-prompts-systematically
