Skip to content
bits
Prompting that works · Lesson 8 of 10

Chain your prompts

Tutor:

Some jobs are too much for one prompt. Not because Claude can't think them through (with thinking on, it handles a lot in one go), but because you want to see, check or steer the steps in between.

That's prompt chaining: split the job into a few fixed steps, and make each step its own call to Claude. The output of one step becomes the input of the next.

Tutor:

Anthropic's most common chain is self-correction, in three calls. Draft: write the thing. Review: check the draft against your criteria and list the problems. Refine: rewrite the draft to fix them.

Why not one prompt that says “write it, check it and fix it”? Because with separate calls you can log each step, test each step on its own, and put a check from your own code between them. Each call also has an easier, narrower job, and that's where the extra accuracy comes from. The price is more calls, so more time and tokens.

import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
async function ask(prompt: string) {
const reply = await client.messages.create({
model: "claude-haiku-5-5", max_tokens: 2000,
messages: [{ role: "user", content: prompt }],
});
return reply.content.flatMap((b) => (b.type === "text" ? [b.text] : [])).join("");
}
const facts = "Dark mode ships 2 November. Turn it on in Settings, then Appearance.";
const draft = await ask(`Write a 60-word launch note for our dark mode. <facts>${facts}</facts>`);
const review = await ask(`<draft>${draft}</draft> Check it against: under 60 words, no jargon, mentions the date. List problems in <review> tags, or reply with only OK.`);
const final = review.trim() === "OK" ? draft : await ask(`<draft>${draft}</draft> <review>${review}</review> Rewrite the draft to fix every problem.`);
TypeScriptUTF-8● lines 12–15: highlighted
Tutor:

Line 15 is a gate: plain code that decides whether the refine step needs to run at all. You can't put a check like that in the middle of a single prompt.

quick check+10 neurons
Tutor:

When is splitting a job into a chain of prompts most worth it?

    Type your answer or tap an option · Enter checks

    Tutor:

    This sandbox runs one prompt at a time, so you'll play the middle of the chain by hand. The draft below has three problems: it's long, it's full of jargon and it never says when dark mode ships (it's 2 November).

    Write the review step. Put the draft in <draft> tags, give your criteria, and ask Claude to list the problems (not rewrite it) in <review> tags.

    Your turn

    Run your prompt and the replies land here.

      • Puts the draft in <draft> tags, not yet
      • Gives criteria, not yet
      • Asks for problems, not a rewrite, not yet
      • Asks for <review> tags, not yet
      • Ran at 1.0, not yet
      run at
      ~0 tokens

      Turn on JavaScript to run prompts.

      Tutor:

      Want to finish the chain by hand? Copy Claude's review, then write a third prompt with the draft and the review in tags, and ask for a rewrite.