Code of the Day
IntermediatePrompt Crafting

Chain-of-thought prompting

Ask the AI to reason step by step before answering — a technique that measurably improves accuracy on multi-step problems.

Using AIIntermediate9 min read
By the end of this lesson you will be able to:
  • Explain why generating intermediate reasoning steps improves AI accuracy
  • Add chain-of-thought instructions to a prompt effectively
  • Identify tasks where chain-of-thought helps vs. adds no value
  • Spot the difference between a conclusion jumped to and a conclusion reasoned through

Ask an AI to name the capital of Germany and it will answer correctly with no reasoning shown. Ask it to determine which of two sorting algorithms is faster for a nearly-sorted list of 10,000 items, and whether you see accurate reasoning depends on something you can control: whether you tell it to think before it answers.

Chain-of-thought prompting is the practice of explicitly asking the model to work through a problem step by step before producing a final answer. It is one of the most reliable levers available for improving accuracy on reasoning-heavy tasks.

Why it helps

A language model generates each token based on what came before. When you ask for a direct answer, the model skips to a token sequence that looks like an answer — which may or may not reflect a correct reasoning path. The model "commits" to a direction very early.

When you ask for step-by-step reasoning first, each reasoning step becomes the context for the next. The model is, in effect, generating its own scratchpad. Errors in an intermediate step are visible — and the subsequent steps can correct course. The conclusion emerges from a chain that's coherent with itself rather than a single leap from problem statement to answer.

This is why the technique is called chain-of-thought: you're asking the model to expose its chain of reasoning as it goes.

Research has shown that adding "Let's think step by step" to prompts significantly improves accuracy on arithmetic, symbolic reasoning, and multi-step logic tasks — even when that phrase is the only change to the prompt. The effect is especially pronounced on problems where the answer requires several intermediate conclusions.

How to invoke it

The phrasing is flexible. Any of these work:

  • "Before answering, break this problem down into steps."
  • "Think through this step by step."
  • "Let's reason through this carefully before reaching a conclusion."
  • "Work through your reasoning, then give your final answer at the end."

The last variant is often the most useful for practical work: it produces visible intermediate steps you can check, followed by a clearly marked conclusion you can act on.

For more complex tasks, you can be more explicit about the structure:

"First, identify what the function is supposed to do. Second, trace through the logic with a concrete example. Third, identify any cases where the logic might fail. Finally, give me your assessment."

Before and after

Here is a logic problem without chain-of-thought:

Prompt: Alice is older than Bob. Bob is older than Carol. Is Alice older than Carol? Response: Yes.

Correct, but the model jumped directly to the answer. Now with chain-of-thought:

Prompt: Think step by step, then answer: Alice is older than Bob. Bob is older than Carol. Is Alice older than Carol? Response: Step 1: Alice is older than Bob. Step 2: Bob is older than Carol. Step 3: By transitivity — if Alice > Bob and Bob > Carol, then Alice > Carol. Final answer: Yes, Alice is older than Carol.

The answer is the same, but the reasoning is visible. Now try a harder variant:

Alice is older than Bob. Bob is older than Carol. Carol is older than Dave. Dave is older than Alice. Who is oldest?

Without chain-of-thought, the model might output a name with no reasoning. With it, the contradiction between "Dave is older than Alice" and "Alice is older than Bob...Carol...Dave" becomes visible in the reasoning chain, and the model can surface it rather than silently picking an answer.

When to use it

Chain-of-thought is worth using when:

  • The task requires multiple logical steps to reach a conclusion
  • You're debugging an algorithm and need to trace through execution
  • You're asking for a recommendation that should weigh multiple factors
  • You want to verify the model's reasoning, not just its conclusion
  • The stakes are high enough that a confident wrong answer would be costly

Chain-of-thought adds tokens. For a factual lookup ("what does the sorted() function return in Python?"), asking for step-by-step reasoning wastes tokens and adds noise without improving accuracy. Reserve it for tasks where reasoning steps genuinely exist and matter.

Checking the chain

One underused benefit of chain-of-thought prompting: you can verify the intermediate steps, not just the conclusion. If a step looks wrong, you can interrupt:

"In step 3 you said X. But doesn't Y mean that X can't be true in this case?"

This turns chain-of-thought into a collaborative reasoning process rather than a black box that produces conclusions. The visible chain gives you something to engage with.

Where to go next

You've now seen how to structure a prompt, assign a role, and elicit explicit reasoning. The next lesson is about what to do when the output still isn't right: iterating on prompts — the strategies for adjusting, redirecting, and narrowing a conversation until you get what you actually need.

Knowledge check

  1. 1.
    Why does asking for step-by-step reasoning improve accuracy on multi-step problems?
  2. 2.
    Which of the following tasks would most benefit from chain-of-thought prompting? Select all that apply.
  3. 3.
    Chain-of-thought prompting should be used for every prompt to maximise the quality of AI responses.
Finished reading? Mark it complete to track your progress.

On this page