Chain-of-Thought (CoT) โ Prompting Guide & Examples
Chain-of-Thought prompting guides the AI to break down complex problems into intermediate reasoning steps before arriving at a final answer. Instead of jumping to conclusions, the model shows its work โ dramatically improving accuracy on math, logic, and multi-step reasoning tasks.
How It Works
You add phrases like 'Let's think step by step' or provide a worked example showing intermediate reasoning. The model then mimics this pattern, producing explicit reasoning chains that lead to more accurate conclusions. This works because LLMs are better at sequential reasoning than parallel leaps.
When to Use
Use CoT for math problems, logic puzzles, multi-step reasoning, code debugging, complex analysis, and any task where showing intermediate work improves accuracy. Especially powerful for tasks where the model would otherwise make reasoning errors.
Model-Specific Tips
ChatGPT / GPT-4
GPT-4 and later respond extremely well to CoT. Add 'Think step by step' or provide a worked example. Works with both system and user prompts.
Claude
Claude excels at CoT natively. Use 'Let me work through this systematically' or place reasoning instructions in the system prompt. Claude's extended thinking mode automates this.
Gemini
Gemini supports CoT well. Use 'Break this down step by step' in your prompt. Gemini 1.5 Pro handles long reasoning chains particularly well.
Pros & Cons
Pros
- โ Dramatically improves accuracy on reasoning tasks
- โ Makes model thinking transparent and debuggable
- โ Works across all major models
- โ Easy to implement โ just add 'step by step'
Cons
- โ Uses more tokens (higher cost)
- โ Slower responses due to longer outputs
- โ Can introduce verbose unnecessary steps on simple tasks
- โ Reasoning chains can still contain errors
Example Prompts
A store sells apples for $2 each. If I buy 3 apples and pay with a $10 bill, how much change do I get? Let's think step by step.
Analyze this business scenario step by step: A SaaS company has 10,000 users paying $29/mo with 5% monthly churn. They want to reach $5M ARR. What needs to change?
Debug this code by reasoning through the execution step by step: ``` function sum(arr) { let total; for(let i = 0; i <= arr.length; i++) { total += arr[i]; } return total; } ```