Chain-of-thought (CoT)

In one sentence

Have the model write intermediate steps before the answer: it buys accuracy on multi-step problems at the cost of tokens and latency. Reasoning models do it natively, so set their effort knob instead.

Analogy: Doing long division on paper instead of in your head: slower and uses more paper, but you make fewer mistakes. And the scratch work is not what you hand in.

Instruct CoT only on non-reasoning models; either way, parse out the answer and keep the reasoning out of the UI.

How it works

  • Each generated token is extra computation later tokens build on, so a multi-step problem stops being one leap.
  • Trigger it with worked examples (few-shot CoT) or just "Let's think step by step" (zero-shot CoT).
  • Put reasoning first, inside <thinking> tags; show users only the answer and log the steps for evals.
  • Gains concentrate on math and symbolic reasoning; elsewhere they are much smaller.
  • Not a faithful explanation: models often omit what actually drove the answer; never use it for audits.

Check yourself

Answer to mark it learned; your answers aren't scored.

You move a multi-step pricing prompt from a small non-reasoning model to a reasoning model (o-series, or Claude with thinking). The prompt still ends with "Let's think step by step" and asks for reasoning in <thinking> tags. What do you change?

Go deeper

Full explanation

Chain-of-thought means the model writes intermediate reasoning before the final answer. Every generated token is extra computation that later tokens can condition on, so a problem with several dependent steps (math, logic, multi-constraint decisions) stops being a single leap.

Two ways to trigger it:

  • Few-shot CoT (Wei et al. 2022): examples that show worked reasoning.
  • Zero-shot CoT (Kojima et al. 2022): just add "Let's think step by step."

Reasoning models (OpenAI's o-series and GPT-5 family, Claude with extended or adaptive thinking, DeepSeek-R1, Gemini thinking models) are trained with RL to do this natively. Don't tell them to think step by step: set depth with the provider's knob (OpenAI's reasoning_effort, Claude's effort, a thinking budget on older models) and spend the prompt on the goal and constraints. See Reasoning models & test-time compute.

In production:

  • Separate thinking from the answer with <thinking> and <answer> tags, or a reasoning field before answer in a schema; parse only the answer.
  • Don't show raw reasoning to users. It can hold wrong turns, leaked instructions or unsafe text; log it for debugging and evals.
  • Reasoning goes first. An explanation written after the answer is a rationalization and buys no accuracy.
  • It is not a faithful explanation. Models often omit what actually drove the answer (Turpin et al. 2023), so never use it as audit evidence.
Code Zero-shot CoT with tagged reasoning and answer
pythonZero-shot CoT with tagged reasoning and answer
import re
import anthropic

client = anthropic.Anthropic()
MODEL = "claude-haiku-4-5"  # any chat model

PROMPT = """{question}

Think through the problem step by step inside <thinking> tags.
Then give only the final result inside <answer> tags."""

def solve(question: str) -> tuple[str, str]:
    r = client.messages.create(
        model=MODEL,
        max_tokens=1500,  # headroom: the reasoning eats tokens before <answer>
        messages=[{"role": "user", "content": PROMPT.format(question=question)}],
    )
    text = r.content[0].text
    answer = re.search(r"<answer>(.*?)</answer>", text, re.S)
    thinking = re.search(r"<thinking>(.*?)</thinking>", text, re.S)
    if not answer:  # truncated or format ignored: retry or flag, never guess
        raise ValueError("no <answer> block")
    # Log the reasoning for debugging and evals; show the user only the answer
    return answer.group(1).strip(), thinking.group(1) if thinking else ""

# Reasoning mode: drop the CoT instruction and enable native thinking instead.
# Claude 4.6+: thinking={"type": "adaptive"}, output_config={"effort": "medium"}
# Older (e.g. Haiku 4.5): thinking={"type": "enabled", "budget_tokens": 4000}
Real example

A billing bot gets: "Annual plan, $240, cancelled after 5 full months; refund the unused months minus a $20 fee." Asked for just the number, a small non-reasoning model can jump to a plausible wrong figure. With CoT inside <thinking>: $240 / 12 = $20 a month; 7 unused months = $140; minus $20 = $120. The trail costs ~100 extra output tokens (~1–2 s at typical decode speeds). The user sees only $120; the steps go to logs, where an eval can check each one.

Trade-offs +3 · −3

+ You gain

  • Large accuracy gains on multi-step math, logic and planning.
  • The trace makes failures debuggable and gradable step by step.
  • One prompt line or one API parameter; no training.

− You pay

  • More output tokens, which are decoded serially and priced higher: slower and costlier.
  • The trace can be unfaithful: plausible reasoning that did not drive the answer.
  • Little or no gain on lookup, extraction or simple classification.

Use it when

Multi-step problems (math, logic, multi-constraint decisions, plans) on non-reasoning models, or whenever you need a trace for debugging and evals and can afford a few extra seconds.

Avoid it when

Reasoning models (use the effort knob), latency-critical simple tasks like extraction or routing, or as a user-facing justification of the decision.

Numbers to know 5
  • Zero-shot CoT (Kojima 2022): InstructGPT went 17.7% → 78.7% on MultiArith and 10.4% → 40.7% on GSM8K.
  • Few-shot CoT (Wei 2022): PaLM 540B on GSM8K 17.9% → 56.9%; gains appeared only at ~100B+ parameters.
  • Sprague et al. 2024 meta-analysis: CoT's benefit concentrates on math and symbolic reasoning, with much smaller gains elsewhere.
  • Anthropic 2025: reasoning models mentioned a hint they had used only ~25% (Claude 3.7 Sonnet) and ~39% (DeepSeek-R1) of the time.
  • Reasoning and thinking tokens bill as output tokens, even when hidden or summarized. On Claude 4.6+, depth is set by adaptive thinking plus effort; budget_tokens is rejected from 4.7 on (late 2026).
Common pitfalls 4
  • Adding "think step by step" to o-series, R1 or Claude with thinking: redundant, and OpenAI advises against it.
  • max_tokens too small: the reasoning eats the budget and the answer never arrives.
  • Asking for the explanation after the answer: post-hoc rationalization, no accuracy gain.
  • Shipping raw reasoning to the UI or treating it as an audit trail.
Interview questions 2

Answer out loud first, then reveal.

When does chain-of-thought help, and when is it a waste?Show answer

It helps when the answer depends on several intermediate steps: arithmetic, logic, multi-constraint decisions, planning. That's where the published gains are; PaLM on GSM8K roughly tripled. It's mostly a waste on lookup, extraction or routing, where it adds latency and cost for nothing, and it's redundant on reasoning models, where I tune effort instead. Output tokens are the slowest and priciest part of a call, so I decide per task with an eval comparing accuracy, p95 latency and cost.

Compliance wants to show users the model's reasoning as the explanation for a decision. Your take?Show answer

I'd push back. Chain-of-thought isn't a faithful explanation: models change answers because of cues their reasoning never mentions, and reasoning models disclosed a planted hint only a minority of the time. Raw traces can also leak system instructions or contain abandoned wrong turns. If we need explainability, I'd generate a separate user-facing rationale grounded in cited sources, keep the raw trace internal for debugging, and base the audit on inputs, retrieved evidence and the deterministic rules we applied.