How to Use Chain of Thought Prompting Without Wasting Tokens
Chain of thought prompting with copy-paste templates, runnable code, how it compares to few-shot and ReAct, and when it just burns tokens.

Chain of thought prompting means asking a model to work through a problem in visible steps before it commits to an answer, instead of producing the answer directly. The minimal version is one line: "Think step by step, then answer." The useful version also says what to reason about, where the reasoning goes, and where the final answer goes so your code can extract it.
It helps on tasks with dependent steps: date and unit math, rules with several conditions, debugging, and classification with awkward edge cases. It wastes tokens on lookups, reformatting, and extraction, and it's mostly redundant on models that already reason in a built-in thinking phase before they reply. Below: how it works, templates you can paste, code for building the prompt and pulling out the answer, a comparison with few-shot, ReAct, and tree of thought, and the mistakes that quietly cost money.
How chain of thought prompting works#
A language model produces one token at a time, and each token is conditioned on everything before it. If the model answers "no" immediately, that one token has to carry the whole computation. If it first writes "06:40 plus 2 hours is 08:40, plus 35 minutes is 09:15," each intermediate value becomes context that the next step can read. The reasoning text is scratch paper.
Two things follow. The reasoning has to come before the answer, because an explanation written after the answer is a justification, not a computation, and it won't catch a wrong answer. And the quality of the steps matters more than their presence. Three vague sentences followed by a guess isn't reasoning. Prompts that say what to check produce better steps than prompts that only say "think."
How to write a chain of thought prompt#
Start small and add structure only when the output needs it.
[TASK DESCRIPTION]
Think through the problem step by step before answering. Then give your final answer inside <answer></answer> tags, with nothing after the closing tag.
[INPUT]
Why this wording: "step by step" triggers the behavior, "before answering" fixes the order, and the answer tags give your code a reliable string to pull out. Anthropic's chain of thought guidance recommends this tag pattern for manual chain of thought on Claude when thinking is off, and the same prompt works with ChatGPT and Gemini.
When the task has known failure modes, name the checks rather than hoping the model finds them:
You are reviewing [KIND OF INPUT, e.g. a SQL migration].
Work through these in order and write a short note for each:
1. What the input is trying to do.
2. [SPECIFIC CHECK 1, e.g. any column dropped or renamed that other tables reference]
3. [SPECIFIC CHECK 2, e.g. any operation that locks a large table]
4. Anything that contradicts [CONSTRAINT].
Then give your verdict inside <answer></answer> tags as exactly one of: [LABEL A], [LABEL B], [LABEL C].
<input>
[INPUT]
</input>
Why this wording: the numbered list makes order and completeness explicit, which Anthropic's docs recommend whenever the steps matter. The fixed label set keeps the answer parseable. Putting the input in its own tags separates data from instructions, so a sentence inside the input that reads like a command is less likely to be obeyed.
The third pattern is a self-check at the end, which the same docs describe as a reliable way to catch errors in coding and math:
[TASK]
Before you finish, verify your answer against [TEST CRITERIA, e.g. the three sample inputs and expected outputs below]. If a check fails, fix the answer and say what changed.
[INPUT]
Why this wording: concrete criteria give the model something to reason against, which beats a general "be careful." One caveat from the docs: Claude Opus 5 already verifies its own work and can over-verify when told to, so on that model the advice is to remove the instruction rather than reword it.
For the surrounding structure, including roles, constraints, and examples, the CoreMesh overview of prompt engineering techniques that work in any AI chat goes deeper. If your main use is code review or debugging, the copy-paste prompts for coding already bake in a reason-then-answer shape.
Chain of thought prompting examples you can run#
The code around a chain of thought prompt is short: build the prompt, send it, extract the answer. This script does the first and last steps against a sample response, so you can see the extraction logic without an API key.
import re
TEMPLATE = """{task}
Think through the problem step by step before answering.
Then give your final answer inside <answer></answer> tags,
with nothing after the closing tag.
{input}"""
def build_prompt(task, user_input):
return TEMPLATE.format(task=task, input=user_input)
def extract_answer(text):
match = re.search(r"<answer>(.*?)</answer>", text, re.DOTALL)
return match.group(1).strip() if match else None
prompt = build_prompt(
"Decide whether the shipment arrives before the store opens.",
"Shipment leaves at 06:40 and takes 2 h 35 min. Store opens at 09:00.",
)
print(prompt)
print("-" * 40)
sample_response = """06:40 plus 2 h is 08:40. Plus 35 min is 09:15.
09:15 is after 09:00, so the shipment arrives after opening.
<answer>No, it arrives at 09:15, 15 minutes after the store opens.</answer>"""
print("Extracted:", extract_answer(sample_response))
print("Missing tag ->", extract_answer("Probably no."))
The None case is the important one. If the model skips the tags, you want to detect that and retry, not parse a paragraph of reasoning as if it were the answer.
With the Claude API, the current advice is to let the model's built-in thinking do the reasoning and to control depth through the effort setting instead of prompt text. Anthropic's docs show this shape:
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=16000,
thinking={"type": "adaptive"},
output_config={"effort": "high"},
messages=[{
"role": "user",
"content": "Decide whether the shipment arrives before the store opens. "
"Shipment leaves at 06:40 and takes 2 h 35 min. Store opens at 09:00.",
}],
)
for block in response.content:
if block.type == "text":
print(block.text)
Two details from the same page: pick content blocks by type rather than by position, because a response can begin with thinking blocks, and leave room in max_tokens for the thinking itself.
Chain of thought vs few shot, ReAct, and tree of thought#
These names get mixed up because they overlap. Few-shot is about examples. Chain of thought is about visible reasoning. ReAct and tree of thought are control patterns built on top of reasoning.
| Technique | What you add to the prompt | Best for | Cost |
|---|---|---|---|
| Zero-shot chain of thought | An instruction to reason before answering | Multi-step problems with no examples on hand | Longer output |
| Few-shot chain of thought | Worked examples that include the reasoning | Tasks with a consistent method you can demonstrate | Longer input and output |
| Few-shot without reasoning | Input and output pairs only | Format, tone, label vocabularies | Longer input |
| ReAct | Alternating thought, tool call, observation | Tasks that need outside information or actions | Many turns |
| Tree of thought | Several candidate reasoning paths, scored and pruned | Search-like problems with dead ends | Many calls per problem |
Few-shot and chain of thought combine well. Anthropic's docs say to wrap examples in example tags so the model can tell them from instructions, and that worked examples still shape how Claude approaches problems even when it reasons in thinking blocks. Present each example as the problem, the method to apply, and the expected answer. For how many examples to include, see how few shot prompting works and how many examples to use.
ReAct is what most tool-using agents do: the model writes a short thought, picks a tool, reads the result, and repeats until it has what it needs. If you're calling an API with tools enabled, you're getting this already, and adding "think step by step" to the system prompt mostly makes each thought longer.
Tree of thought is rarely worth building yourself. It means generating several reasoning branches, scoring them, and dropping the weak ones, which multiplies the cost of every answer. It's a research technique for puzzles with dead ends, not a default for production prompts.
When chain of thought helps and when it wastes tokens#
So the question isn't whether chain of thought improves reasoning in general. It's whether this particular task has any reasoning in it.
| Task | Chain of thought | Why |
|---|---|---|
| Arithmetic, dates, unit conversion | Helps | Intermediate values need to exist somewhere |
| Rules with several conditions (eligibility, policy) | Helps | Each condition gets checked instead of pattern-matched |
| Debugging from a stack trace | Helps | Hypothesis then evidence beats a guess |
| Classification with ambiguous edge cases | Often helps | Forces the model to name the deciding feature |
| Extract a field from a document | Wastes tokens | Nothing to reason about; a format instruction is enough |
| Rewrite in a different tone | Wastes tokens | Style, not logic |
| Facts the model already knows | Wastes tokens | Reasoning adds words, not accuracy |
| Any task on a model with thinking always on | Redundant | The model already reasons before it replies |
That last row is the one that changed most recently. According to Anthropic's docs, thinking is on by default on Claude Opus 5, Sonnet 5.5, Sonnet 5, and Haiku 5.5 when you omit the thinking parameter, and always on for Claude Fable 5.1, Mythos 5.1, Fable 5, Mythos 5, and Opus 5.5. On those models the docs say to rely on extended thinking rather than manual chain of thought, and to pick a lower effort level if cost or latency matters. They also warn that a prompt asking Claude to write out its reasoning, for example in thinking tags, may be declined on Fable 5.1, Fable 5, Opus 5.5, Opus 5, and Sonnet 5.5. On Claude Opus 4.6 through 4.8 and Sonnet 4.6, thinking is off unless you turn it on, and manual chain of thought still applies.
The same page makes a point that holds across vendors: general instructions tend to beat prescriptive ones. A prompt like "think thoroughly" often produces better reasoning than a hand-written step-by-step plan, because the model's own decomposition frequently goes further than a human would specify. Save numbered steps for cases where a specific check must happen, like the review template above.
When you want a cheap, direct answer, say so:
Answer with only [FORMAT, e.g. a JSON object with the keys "label" and "confidence"]. Do not explain your reasoning.
[INPUT]
Why this wording: models tend to add explanation by default. Naming the exact output and ruling out the explanation keeps tokens down on tasks that have nothing to reason about.
Checking that the model actually reasoned#
Once chain of thought is in production, the risk is drift. The model starts answering first, or writes two words of reasoning, or adds a sign-off after the answer tag that breaks your parser. A few string checks catch these shapes in evals and logs.
const checks = {
hasAnswerTag: (t) => /<answer>[\s\S]*?<\/answer>/.test(t),
answerIsLast: (t) => /<\/answer>\s*$/.test(t),
reasonsBeforeAnswer: (t) => {
const i = t.indexOf("<answer>");
return i > 0 && t.slice(0, i).trim().split(/\s+/).length >= 15;
},
};
const samples = {
good:
"06:40 plus 2 h is 08:40. Plus 35 min is 09:15. 09:15 is after 09:00, " +
"so it arrives after opening and the answer is no.\n<answer>No</answer>",
answerFirst:
"<answer>No</answer>\nBecause 06:40 plus 2 h 35 min is 09:15, which is after 09:00.",
noTag: "It arrives at 09:15, so no.",
trailingChatter:
"08:40, then 09:15, which is after opening.\n<answer>No</answer>\n" +
"Let me know if you need anything else!",
};
for (const [name, text] of Object.entries(samples)) {
const results = Object.entries(checks).map(
([k, fn]) => `${k}=${fn(text) ? "ok" : "FAIL"}`
);
console.log(name.padEnd(16), results.join(" "));
}
The checks are crude, and a word count says nothing about quality. But they catch the shapes that break pipelines, and they cost nothing to run on every response. For a real quality check, Anthropic's docs describe a chaining pattern: generate a draft, have the model review it against criteria in a second call, then refine in a third. Each step is a separate call you can log, evaluate, or branch on.
Common mistakes with chain of thought prompting#
- Asking for the answer first and the reasoning second. The reasoning becomes a rationalization. Put the answer at the end, every time.
- Parsing the whole response as the answer. Use tags or a fixed final line, and handle the case where the tag never shows up.
- Showing the reasoning to end users. Scratch work belongs to the model and your logs. Strip it before display or collapse it.
- Stacking "think step by step" on a model with built-in thinking. Redundant at best. On several current Claude models a request for reasoning in thinking tags may be declined; use the effort setting instead.
- Writing a rigid ten-step plan where one general instruction would do. Over-prescription boxes in reasoning that would have been better on its own.
- Too small a max_tokens. Reasoning plus answer can get cut off, and if the closing tag never arrives the answer is gone. Raise the limit, and on Claude leave room for thinking blocks as well.
- Mixing the input into the instructions. Wrap it in its own tags so a command-shaped sentence in the data doesn't get followed.
- Carrying self-check instructions across models. Anthropic's docs single out Claude Opus 5 as a model where verification prompts tuned for earlier models cause over-verification and should be removed.
- Treating one good run as proof. Run the prompt against a small set of inputs with known answers, with and without the reasoning instruction, and compare both accuracy and output length.
Quick reference#
- Use chain of thought for math, dates, multi-condition rules, debugging, and ambiguous classification.
- Skip it for extraction, reformatting, tone changes, and facts the model already knows.
- Reasoning first, answer last, answer inside tags.
- Prefer "think thoroughly" over a prescriptive plan; add numbered steps only for checks that must happen.
- Add a self-check with concrete criteria for code and math, except on Claude Opus 5.
- On models with thinking on by default or always on, drop manual chain of thought and tune effort instead.
- Select content blocks by type, and leave room in max_tokens for thinking.
- Validate the response shape: tag present, tag last, reasoning before it.
- Measure accuracy and token count on a fixed test set before shipping.
Quick answers
What is the chain of thought prompting paper?
The usual reference is "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models" by Jason Wei and colleagues, published in 2022. It showed that few-shot examples containing reasoning steps improved results on multi-step problems. A second 2022 paper by Takeshi Kojima and colleagues introduced the zero-shot "Let's think step by step" version.
Does chain of thought prompting improve reasoning?
On multi-step tasks like arithmetic, date math, and rule checking, yes, because intermediate results get written down where later steps can use them. On lookups, formatting, and extraction it adds output tokens without changing the answer. On models with built-in thinking the benefit mostly disappears, since the model already reasons before replying.
What's the difference between chain of thought and few shot prompting?
Few-shot adds examples of inputs and outputs so the model copies the pattern; chain of thought asks for visible reasoning before the answer. They combine well, and the original chain of thought paper used few-shot examples that included the reasoning.
Chain of thought vs ReAct: which should I use?
ReAct interleaves reasoning with tool calls and observations, so it suits tasks that need outside information or actions. Chain of thought is a single response with reasoning followed by an answer. If you're using an API with tools enabled, you're already getting ReAct-style behavior.
Should I add "think step by step" when using Claude?
Anthropic's docs say that on current Claude models with thinking on, you should rely on thinking and the effort setting rather than manual chain of thought, and that a request to write reasoning in thinking tags may be declined on Fable 5.1, Fable 5, Opus 5.5, Opus 5, and Sonnet 5.5. Manual chain of thought remains the fallback when thinking is off, which is the default on Opus 4.6 through 4.8 and Sonnet 4.6.
Did this solve it?
One tap. No account.
Sorry about that. What was missing?
from 0 readers
Saved you an hour? Send a tip.
USDC or ETH on Base, Ethereum, Arbitrum and more. Keeps the notes free and the examples running.
Network
0xc783bc5c3fa14cEC3f09A22284bC91C5AF0d59e1
On a computer? Scan the code with your phone wallet, or copy the address.
Pick the network your wallet or exchange uses. USDC works on all six; ETH on Base, Ethereum, Arbitrum and Optimism. Don't send on Tron or Solana: this address doesn't exist there. Tips are optional and unlock nothing; every guide stays free.
Discussion
Start the discussion
Next note