Chain-of-Thought Reasoning
Chain-of-Thought (CoT) reasoning is a prompting technique that encourages large language models to produce explicit intermediate reasoning steps before arriving at a final answer, mimicking the way humans "think out loud" to solve complex problems. It matters enormously in modern AI because it dramatically improves LLM performance on multi-step tasks — arithmetic, logic, planning, and agentic decision-making — without any additional model training. The counterintuitive fact: simply adding the phrase "Let's think step by step" to a prompt can more than double a model's accuracy on math word problems.
A language model predicts tokens one at a time, and each token it generates becomes part of the context for the next prediction. When you force a model to write out reasoning steps, each intermediate step conditions the next step, effectively letting the model "use the page as scratch paper." The "aha moment" is realizing that CoT is not a training trick or a new architecture — it is a prompting strategy that exploits the autoregressive nature of transformers to unlock reasoning that the model already has latent capability for, but cannot access in a single forward pass.
How It Works
At its core, Chain-of-Thought works by conditioning the model's next-token prediction on an explicitly generated reasoning trace. Let's build up the mechanism from first principles. A standard language model computes the probability of an answer given a question :
Explanation: The model maps a question directly to an answer in one shot, with no intermediate steps visible. With Chain-of-Thought, we instead decompose this into a sequence of reasoning steps before producing the answer:
Explanation: The answer is now computed by marginalizing over all possible reasoning traces ; in practice we sample one trace greedily or with low temperature. Because the model generates first, then conditioned on , and so on, each step narrows the token distribution toward logically consistent continuations:
Explanation: This is just the chain rule of probability applied to the reasoning sequence — each step depends on everything that came before it, making earlier steps act as a working memory. Here is the most minimal Python illustration of the difference between standard prompting and CoT prompting using the OpenAI API: ```python from openai import OpenAI client = OpenAI() # uses OPENAI_API_KEY from environment question = "A farmer has 17 sheep. All but 9 run away. How many sheep remain?"
# ── Standard prompt ────────────────────────────────────────────────────────── standard_response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": question}], temperature=0, ) print("Standard:", standard_response.choices[0].message.content)
# → Often: "8" (wrong — subtracts instead of reading "all but 9")
# ── Chain-of-Thought prompt ─────────────────────────────────────────────────── cot_response = client.chat.completions.create( model="gpt-4o", messages=[{ "role": "user", "content": question + "\n\nLet's think step by step." }], temperature=0, ) print("CoT:", cot_response.choices[0].message.content)
# → "The phrase 'all but 9' means 9 remain. Answer: 9" (correct) ``` There are three main flavours of CoT prompting in practice:
| Variant | How it works | Best for |
|---|---|---|
| Zero-shot CoT | Append "Let's think step by step." | Quick wins, no examples needed |
| Few-shot CoT | Provide 3–8 worked examples in the prompt | Consistent format, domain tasks |
| Auto-CoT | Model generates its own examples | Large-scale pipelines |
Here is a few-shot CoT prompt builder in Python, which is the approach most commonly used in agentic systems: ```python def build_cot_prompt(examples: list[dict], question: str) -> str: """ examples: list of {"question": str, "reasoning": str, "answer": str} """ prompt_parts = [] for ex in examples: prompt_parts.append( f"Q: {ex['question']}\n" f"Reasoning: {ex['reasoning']}\n" f"A: {ex['answer']}" ) prompt_parts.append(f"Q: {question}\nReasoning:") return "\n\n".join(prompt_parts)
examples = [ { "question": "Roger has 5 tennis balls. He buys 2 more cans of 3 balls each. How many tennis balls does he have?", "reasoning": "Roger starts with 5 balls. 2 cans × 3 balls = 6 new balls. 5 + 6 = 11.", "answer": "11", }, { "question": "A store had 23 apples. They sold 15 and received a shipment of 7. How many now?", "reasoning": "Start: 23. Sold: 23 - 15 = 8. Received: 8 + 7 = 15.", "answer": "15", }, ] prompt = build_cot_prompt( examples, question="There are 48 students in a class. Half go on a field trip. Then 6 return early. How many are still on the trip?" ) print(prompt) ```
Jason Wei is a researcher at Google Brain (later OpenAI) who co-authored the landmark 2022 paper "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models," which introduced the term and the systematic study of CoT. His paper demonstrated that CoT only emerges as a useful technique above a certain model scale threshold (roughly 100B parameters for the models of 2022), a finding that catalyzed enormous subsequent research into why scale unlocks reasoning. Surprisingly, Wei originally joined Google Brain as a part-time contractor while completing his undergraduate degree.
Takeshi Kojima, a researcher at the University of Tokyo working with collaborators at Google, discovered in 2022 that simply appending "Let's think step by step" to a prompt — with no worked examples at all — yields dramatic accuracy improvements across benchmarks. This zero-shot variant was arguably more surprising than few-shot CoT because it required no human-crafted reasoning examples, suggesting the model had internalized reasoning templates from pretraining. His finding shifted the field's understanding of what pretraining on internet text implicitly teaches language models.
Intuition
Imagine you are asked to calculate a restaurant tip in your head with a single blink — hard, error-prone. Now imagine you are given a napkin to write on. You jot: "bill is 4.70, double it: $9.40." The napkin did not make you smarter; it gave your existing arithmetic skill a workspace. Chain-of-Thought is that napkin for a language model. The model always had the knowledge of arithmetic, logic, or planning inside its weights, but a single forward pass (answering in one go) is like blinking — there is nowhere for intermediate thoughts to go. By generating text step by step, each sentence the model writes becomes a visible "thought on the napkin" that the model can build on for the next sentence. The reasoning quality improves not because the model learned anything new, but because the scratchpad lets partial results persist and compound.
Historical Development
Origins · 1 minhow this was discovered
Why It Matters
Prerequisites
What This Leads To
See Also
Prompt Engineering · ReAct Framework · Self-Consistency · Tree of Thoughts · Retrieval-Augmented Generation · LLM Agents · In-Context Learning