Chain-of-Thought Prompting
debt(d9/e1/b3/t5)
Closest to 'silent in production until users hit it' (d9). No detection_hints or tools are specified for this term. Misuse of CoT (e.g., applying it to simple lookups, truncating reasoning output, or ordering the answer before the reasoning) produces no errors or warnings — failures manifest as degraded accuracy, higher latency, or inflated token costs that only become visible through user-facing quality issues or billing surprises in production.
Closest to 'one-line patch or single-call swap' (e1). The quick_fix is literally appending 'Think step by step before answering.' to a system prompt, and correcting misuse (removing CoT from inappropriate tasks, reordering reasoning before conclusion) is a single-prompt edit.
Closest to 'localised tax' (b3). The choice affects individual prompts or the system prompt of a specific LLM integration. It doesn't spread across the codebase architecturally, but within the component that uses it, every maintainer must understand when to apply or remove it, and poor CoT examples require ongoing iteration.
Closest to 'notable trap' (t5). The misconception is explicitly documented: developers assume 'think step by step' universally improves results, but it can degrade performance on simple tasks and adds latency/token cost. The ordering trap (reasoning must precede the conclusion) is also a documented gotcha. These are well-known but non-obvious surprises that most developers learn the hard way.
Also Known As
TL;DR
Explanation
Chain-of-thought (CoT) prompting adds reasoning steps between the question and the answer. Instead of 'Q: What is 15% of 240? A: 36', you prompt 'think step by step' and get 'First, 10% of 240 is 24. Then 5% is 12. So 15% is 24 + 12 = 36. Answer: 36'. The reasoning steps force the model to decompose the problem, reducing the chance of incorrect short-circuit answers. Few-shot CoT provides example reasoning chains in the prompt; zero-shot CoT uses the phrase 'Let's think step by step'. Extended variants include Tree-of-Thought (exploring multiple reasoning paths) and ReAct (interleaving reasoning with tool calls). CoT is most effective for multi-step reasoning, arithmetic, logic, and code generation tasks.
Watch Out
Common Misconception
Why It Matters
Common Mistakes
- Using CoT for every prompt regardless of task type — adds tokens and latency with no benefit on simple lookups.
- Asking the model to reason after giving the answer — the reasoning must come before the conclusion to influence it.
- Truncating CoT output to save tokens — the reasoning steps are what produce the correct answer; cutting them breaks the technique.
- Not iterating on CoT examples — few-shot CoT quality depends heavily on the quality of the example reasoning chains you provide.
Avoid When
- Simple factual retrieval tasks (e.g., 'What is the capital of France?') where CoT adds unnecessary latency without improving accuracy.
- Real-time applications with strict latency requirements, since step-by-step reasoning roughly doubles token generation time and response delay.
- Tasks where the model lacks domain knowledge, as verbose reasoning chains may amplify and expose hallucinations rather than correct them.
- Summarization or creative writing where intermediate steps can dilute coherence and the task doesn't require explicit problem decomposition.
When To Use
- When asking an LLM to solve multi-step math problems, logic puzzles, or reasoning tasks where intermediate steps directly affect the final answer.
- When generating code or debugging complex logic where the model needs to explain its approach before writing the solution.
- When accuracy matters more than speed and the task involves decomposable subproblems (e.g., extracting information, comparing options, making judgments).
- When you suspect the model might give a confident but incorrect short-answer and need visibility into its reasoning to catch errors or hallucinations.
Code Examples
// ❌ Demanding a direct answer for complex reasoning — no step-by-step
$response = $client->messages->create([
'model' => 'claude-sonnet-4-20250514',
'messages' => [[
'role' => 'user',
'content' => 'Is it safe to delete all orders older than 30 days? Answer yes or no.'
// LLM forced to guess — misses edge cases, no reasoning surfaced
]]
]);
// ✅ Chain-of-thought: instruct the model to reason step-by-step
$response = $client->messages->create([
'model' => 'claude-sonnet-4-20250514',
'max_tokens' => 1000,
'system' => 'Think through problems step by step before giving your final answer.',
'messages' => [[
'role' => 'user',
'content' => 'Is it safe to delete all orders older than 30 days? '
. 'Consider: legal retention requirements, reporting dependencies, '
. 'foreign key constraints, and customer refund windows. '
. 'Show your reasoning, then give a recommendation.'
]]
]);
// For structured CoT: ask for explicit reasoning blocks
// The model will surface its reasoning before concluding —
// allowing you to audit the logic, not just the answer