# What is prompt chaining?

Date: 2024-05-10 · Author: Robert Scales · https://guidetoartificialintelligence.com/en/learn/prompt-chaining/

**Answer:** Prompt chaining means breaking a large job into a sequence of smaller prompts, where the output of each step becomes the input of the next. Each step gets the model's full attention, so the result is usually more accurate, and when something goes wrong you can see exactly which step to fix.

When you ask a chatbot to research, plan, write and polish something in a single message, you are asking it to do four jobs at once. Anthropic's guide to its Claude models compares this to juggling: the more balls in the air, the more likely one drops. Prompt chaining handles the jobs one at a time. You write a prompt for the first step, take its output, and paste it into the prompt for the next step, until the chain reaches the finished result.

The idea has a research history. In a 2021 paper, Tongshuang Wu, Michael Terry and Carrie J. Cai described "AI Chains", in which the output of one language-model step feeds the next. In their study with 20 participants, chaining improved the quality of results and made the system easier to understand and steer. People also tested single links of the chain on their own to find where a problem began, much as programmers test one function at a time.

## Why a chain beats one long prompt

Three benefits come up again and again.

**Focus.** Each prompt has a single, clear objective, so instructions don't compete. A model told to "be creative, accurate, brief and well-sourced" all at once tends to trade one against another.

**Visibility.** You see every intermediate result. If the final article is weak, you can tell whether the outline was thin or the drafting went off course.

**Control.** You can edit what passes between steps. If the outline is missing a point, you add it before the draft is written, instead of rewriting the draft afterwards.

*A Beginner's Guide to ChatGPT* already advised breaking a task into steps as one way to give the model better context. Chaining turns that advice into a deliberate method with a clear hand-off at each step.

## A worked four-step chain

Suppose you need a 600-word article for a community newsletter on how to start composting at home. Here is a chain you can run in any chatbot, ideally with each step in a fresh chat, so the only context is what you pass along.

**Step 1: Research outline.**

```prompt
I'm writing a 600-word newsletter article for homeowners who have never composted. Create an outline with 5 sections. Under each section, list the key points and any facts a reader would need. Mark with [CHECK] every fact that I should verify before publishing. Return only the outline inside <outline> tags.
```

*Hand-off:* read the outline, verify or correct the [CHECK] items using reliable sources such as your city's waste-management pages, and remove anything you don't want.

**Step 2: Draft.**

```prompt
Write a 600-word article from the outline below. Audience: homeowners new to composting. Tone: friendly and practical. Use every point in the outline and add no new facts.
<outline>
[paste your corrected outline]
</outline>
```

*Hand-off:* the draft text.

**Step 3: Critique.**

```prompt
Review the article below against this checklist: (1) Is every claim supported by the outline? (2) Is anything confusing for a beginner? (3) Is any paragraph longer than four sentences? (4) Is it within 550–650 words? List problems only, numbered, with the sentence each one refers to. Do not rewrite the article.
<outline>[paste outline]</outline>
<article>[paste draft]</article>
```

*Hand-off:* the list of problems. Cross out any you disagree with.

**Step 4: Final.**

```prompt
Revise the article below to fix only the problems listed. Keep everything else unchanged. Return the final article and a one-line note for each change you made.
<problems>[paste the list you kept]</problems>
<article>[paste draft]</article>
```

The tags, such as `<outline>` and `<article>`, are simple labels that show the model where each piece of input begins and ends. Anthropic recommends them for chains because they make it easy to pass material from one step to the next without mixing it up with your instructions.

Notice that you are in the chain too. The two most valuable moments are after step 1, where you correct facts before they spread into the draft, and after step 3, where you decide which criticisms to accept.

> **Try it:** Run steps 1 and 2 above in a single prompt ("outline and then write the article"), then run them as a chain in separate chats. Compare the two drafts for accuracy and structure, and note where you were able to step in.

## How do you split a big task into steps?

Start from the finished result and work backwards. Ask what had to exist just before it: a final article needs a reviewed draft, a draft needs an outline, an outline needs facts. Each of those becomes a step.

Give each step one job you can describe in a sentence, and decide what it must hand over. Good hand-offs are concrete: a list, an outline, a table, a set of quotes. Anthropic's examples follow this pattern, such as extracting the relevant quotes from a document in one prompt and answering a question from those quotes in the next, or listing errors in one step and checking the list for misses in another.

Add a checking step wherever a mistake would be costly. A prompt that reviews the previous output against a short checklist, as in step 3, catches problems while they are still easy to fix. When parts of the job don't depend on each other, such as writing a summary for donors and another for volunteers, run them as separate prompts side by side rather than in sequence.

Keep the chain short at first. Three or four steps cover most everyday tasks. If one step keeps producing poor results, test it alone with a few different inputs, as the participants in the AI Chains study did, and improve that prompt before touching the rest.

## Sources

- Chain prompts: https://docs.anthropic.com/claude/docs/chain-prompts
- AI Chains: Transparent and Controllable Human-AI Interaction by Chaining Large Language Model Prompts: https://arxiv.org/abs/2110.01691
- A Beginner's Guide to ChatGPT: https://www.amazon.com/dp/B0BZRRPXZW
