← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · ✎ updated 7d
← Back to glossary

Chain-of-Thought Prompting

AI / ML Beginner
debt(d9/e1/b3/t5)
d9 Detectability Operational debt — how invisible misuse is to your safety net

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.

e1 Effort Remediation debt — work required to fix once spotted

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.

b3 Burden Structural debt — long-term weight of choosing wrong

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.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

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.

About DEBT scoring →

Also Known As

CoT prompting step-by-step reasoning chain of thought reasoning prompts

TL;DR

A prompting technique that instructs an LLM to show its reasoning step-by-step before giving a final answer, significantly improving accuracy on complex tasks.

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

⚠ CoT doesn't help with factual hallucinations—if the model confidently generates a false premise in step 1, all subsequent 'reasoning' will be built on that lie, making the wrong answer sound more plausible. Always verify intermediate facts, especially in domains where the model has poor training data.

Common Misconception

✗ Adding 'think step by step' always improves results. Chain-of-thought helps with tasks that genuinely require multi-step reasoning. For simple factual lookups or classification tasks, CoT adds latency and token cost without accuracy improvement — sometimes it degrades performance by introducing more opportunities for the model to go off-track.

Why It Matters

Without CoT, LLMs answer complex questions by pattern-matching to similar training examples, which produces confident but wrong answers on novel problems. Asking an LLM to diagnose a bug or explain a security vulnerability benefits enormously from forcing it to reason through the code step by step before concluding. For PHP developers integrating LLMs into code review or analysis tools, CoT prompting produces dramatically more accurate and explainable outputs.

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

✗ Vulnerable
// ❌ 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
    ]]
]);
✓ Fixed
// ✅ 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

Added 23 Mar 2026
Edited 26 Jun 2026
Views 178
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 1 ping S 1 ping M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S
No pings yet today
No pings yesterday
Amazonbot 16 PetalBot 15 Ahrefs 11 SEMrush 10 ChatGPT 8 Google 8 Bing 8 Perplexity 6 Scrapy 6 Twitter/X 3 Applebot 2 Baidu 2 Majestic 1 Meta AI 1 Sogou 1 Brave Search 1
crawler 95 crawler_json 4
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Prompt ai_ml A prompt is the text instruction or question you give to an AI tool to tell it what you want it to do or generate.

Every interaction with generative AI starts with a prompt. Learning to write clear, specific prompts is the foundational skill that determines whether AI tools save you time or waste it.

💡 Before sending a prompt, ask yourself: does this include what I want, what format I need, and enough context for a stranger to help me?

Ask Codex about Prompt →
⚡ DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
Append 'Think step by step before answering.' to your system prompt for any task requiring multi-step reasoning or code analysis
🔗 Prerequisites


✓ schema.org compliant