Chain-of-Thought
intermediateA prompting technique where the model generates intermediate reasoning steps before reaching a final answer. Improves accuracy on complex reasoning tasks.
Overview
Chain-of-Thought (CoT) prompting dramatically improves LLM performance on reasoning tasks by asking the model to "think step by step." Instead of jumping directly to an answer, the model breaks down the problem and works through it systematically. This technique emerged from a key insight: LLMs are better at reasoning when they can show their work. By generating intermediate steps, the model can catch errors, maintain context, and build toward correct answers—much like how humans solve complex problems. CoT is particularly effective for math problems, logic puzzles, multi-step planning, and any task that requires connecting multiple pieces of information. It's now considered a fundamental technique in prompt engineering.
Key Concepts
Step-by-Step Reasoning
Breaking complex problems into smaller, manageable steps that the model solves sequentially.
Zero-Shot CoT
Simply adding "Let's think step by step" to a prompt without providing examples. Often surprisingly effective.
Few-Shot CoT
Providing examples that demonstrate the reasoning process, teaching the model the expected format and depth.
Self-Consistency
Generating multiple reasoning chains and selecting the most common answer to improve reliability.
Code Examples
Question: A store sells apples for $2 each. If I buy 3 apples and pay with a $20 bill, how much change should I receive?
Let's think step by step.
# Model Response:
1. First, I need to calculate the total cost of the apples
2. Cost = 3 apples × $2 per apple = $6
3. Next, I subtract the total cost from the payment
4. Change = $20 - $6 = $14
Therefore, I should receive $14 in change.Simply adding "Let's think step by step" triggers systematic reasoning, reducing errors on arithmetic problems.
Example 1:
Q: If a train travels 60 miles in 1 hour, how far does it travel in 2.5 hours?
A: The train travels 60 miles per hour. In 2.5 hours, it travels 60 × 2.5 = 150 miles. The answer is 150 miles.
Example 2:
Q: A recipe calls for 2 cups of flour for 12 cookies. How much flour for 30 cookies?
A: 12 cookies need 2 cups. That's 2/12 = 1/6 cup per cookie. For 30 cookies: 30 × 1/6 = 5 cups. The answer is 5 cups.
Now solve:
Q: A car uses 3 gallons of gas to drive 90 miles. How many gallons for 210 miles?Providing worked examples teaches the model the expected reasoning format and depth.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": """Solve this problem step by step:
A farmer has chickens and cows. He counts 50 heads
and 140 legs. How many chickens and cows does he have?
Think through this carefully, showing each step of
your reasoning."""
}]
)
print(response.content[0].text)Explicitly asking for step-by-step reasoning in the prompt improves accuracy on complex problems.
Real-World Use Cases
- 1Mathematical word problems and calculations
- 2Logic puzzles and deductive reasoning
- 3Multi-step planning and decision making
- 4Code debugging and analysis
- 5Complex question answering requiring synthesis
Practical Tips
- •Use "Let's think step by step" as a quick boost for reasoning tasks
- •For critical applications, use self-consistency (multiple samples + majority vote)
- •Review the reasoning chain, not just the final answer—errors can hide in steps
- •Combine CoT with verification: ask the model to check its own work
- •Adjust chain length to task complexity—simple problems need fewer steps
Common Mistakes to Avoid
- ✗Using CoT for simple tasks where it adds unnecessary tokens
- ✗Not providing enough context for the reasoning to be grounded
- ✗Expecting CoT to fix fundamental knowledge gaps
- ✗Not reviewing reasoning chains for errors in intermediate steps