DEV Community

Luke Fryer
Luke Fryer

Posted on • Originally published at aipromptarchitect.co.uk

Chain-of-Thought Prompting: Advanced Techniques for Complex Reasoning

        <h2>What is Chain-of-Thought Prompting?</h2>
        <p>Chain-of-Thought (CoT) prompting is a technique that instructs an LLM to break down complex problems into intermediate reasoning steps before arriving at a final answer. Instead of asking a model to jump directly to a conclusion, you ask it to <strong>"think step by step"</strong> — and the quality improvement is dramatic.</p>
        <p>Research from Google Brain (Wei et al., 2022) demonstrated that CoT prompting improves accuracy on arithmetic, commonsense, and symbolic reasoning tasks by <strong>up to 40%</strong> on PaLM 540B. The technique is now considered essential for any production prompt that involves logic, analysis, or multi-step decisions.</p>

        <h2>Why CoT Works: The Cognitive Scaffold</h2>
        <p>LLMs are autoregressive — they predict the next token based on all previous tokens. When you force intermediate reasoning steps into the output, those tokens become part of the context for subsequent predictions. In practice, this means:</p>
        <ul>
            <li><strong>Error propagation decreases</strong> — mistakes in early reasoning are visible and self-correctable</li>
            <li><strong>Working memory increases</strong> — intermediate results are externalised as tokens rather than held implicitly</li>
            <li><strong>Decomposition happens naturally</strong> — complex problems are broken into manageable sub-problems</li>
            <li><strong>Transparency improves</strong> — you can audit the model's reasoning process for correctness</li>
        </ul>

        <h2>Zero-Shot Chain-of-Thought</h2>
        <p>The simplest form of CoT requires zero examples. You simply append a trigger phrase to your prompt:</p>
        <pre><code>Analyse this quarterly revenue data and identify the three most significant trends.
Enter fullscreen mode Exit fullscreen mode

Think step by step before giving your final answer.

Kojima et al. (2022) showed that adding "Let's think step by step" to a prompt improved accuracy on MultiArith by 78.7% → 95.5% with zero examples. The key variations that work well in practice:


  • "Think step by step." — The classic trigger
  • "Let's work through this systematically." — More structured flavour
  • "Before answering, break this problem into parts." — Explicit decomposition
  • "Show your reasoning, then provide the final answer." — Separates process from result
        <h2>Few-Shot Chain-of-Thought</h2>
        <p>Few-shot CoT provides explicit examples of the reasoning process you expect. This is significantly more powerful than zero-shot for domain-specific tasks:</p>
        <pre><code>Example:
Enter fullscreen mode Exit fullscreen mode

Q: A company has 150 employees. If 30% work remotely and 40% of remote workers use the premium plan, how many premium remote users are there?

Reasoning:

  1. Remote workers = 150 × 0.30 = 45
  2. Premium remote users = 45 × 0.40 = 18 Answer: 18

Now solve:
Q: A SaaS platform has 2,400 users. If 65% are on free tier and 20% of paid users choose annual billing, how many annual paid users are there?

The model learns how to reason from your examples, not just what to output. For production systems, we recommend 2-3 CoT examples that cover different reasoning patterns the model will encounter.

        <h2>Self-Consistency: Voting on Reasoning Paths</h2>
        <p>Self-consistency (Wang et al., 2022) is a CoT enhancement that samples multiple reasoning paths and selects the most consistent answer. The process:</p>
        <ol>
            <li><strong>Sample</strong> — Generate N chain-of-thought responses (typically 5-10) with temperature > 0</li>
            <li><strong>Extract</strong> — Pull the final answer from each reasoning chain</li>
            <li><strong>Vote</strong> — Select the most frequently occurring answer (majority voting)</li>
        </ol>
        <p>Self-consistency improved accuracy on GSM8K from 56.5% (standard CoT) to <strong>74.4%</strong>. Implementation considerations:</p>
        <ul>
            <li><strong>Cost</strong> — You're making N API calls per question. Use this selectively for high-stakes decisions</li>
            <li><strong>Temperature</strong> — Set between 0.5 and 0.8 for diversity without nonsense</li>
            <li><strong>When to use</strong> — Mathematical calculations, code generation, classification with ambiguous inputs</li>
        </ul>

        <h2>Tree-of-Thought: Exploring Multiple Branches</h2>
        <p>Tree-of-Thought (ToT) extends CoT by allowing the model to explore, evaluate, and backtrack through multiple reasoning branches. Think of it as BFS/DFS on a reasoning tree:</p>
        <pre><code>System: You are solving a complex optimisation problem. At each step:
Enter fullscreen mode Exit fullscreen mode
  1. Generate 3 possible next steps
  2. Evaluate each step's likelihood of reaching the correct solution (score 1-10)
  3. Pursue the highest-scoring path
  4. If you reach a dead end, backtrack and try the next best path

Problem: [your complex problem here]

ToT is most valuable for problems that require planning, search, or creative problem-solving — tasks where the first reasoning path isn't always the best one. It's computationally expensive but powerful for code architecture decisions, strategic analysis, and puzzle-like problems.

        <h2>Structured CoT for Production Systems</h2>
        <p>In production, you want CoT reasoning that's both effective and parseable. Here's a pattern we use at AI Prompt Architect:</p>
        <pre><code>System: You are a code reviewer. Analyse the provided code using this structured reasoning process.
Enter fullscreen mode Exit fullscreen mode

Reasoning Protocol

For each issue found:

  1. IDENTIFY: What specific code pattern or line is problematic?
  2. CLASSIFY: Is this a bug, performance issue, security risk, or style concern?
  3. SEVERITY: Rate 1-5 (1 = minor, 5 = critical)
  4. EXPLAIN: Why is this problematic? What could go wrong?
  5. FIX: Provide the corrected code

Output Format

After completing your analysis, provide a JSON summary:
{
"issues_found": number,
"critical_issues": number,
"summary": "one-line summary"
}

This pattern gives you auditable reasoning and machine-parseable output — critical for automated pipelines.

        <h2>Common CoT Mistakes</h2>
        <ul>
            <li><strong>Over-prompting</strong> — Forcing CoT on simple factual lookups wastes tokens and can reduce accuracy</li>
            <li><strong>Vague triggers</strong> — "Think carefully" is weaker than "Break this into steps: first X, then Y, then Z"</li>
            <li><strong>Ignoring the reasoning</strong> — If you only parse the final answer, you lose CoT's debugging value</li>
            <li><strong>Wrong temperature</strong> — CoT with temperature 0 gives deterministic (but potentially wrong) chains. Use 0.3-0.5 for reliability with some diversity</li>
            <li><strong>No output separation</strong> — Always separate reasoning from the final answer with clear markers like "REASONING:" and "ANSWER:"</li>
        </ul>

        <h2>Model-Specific CoT Behaviour</h2>
        <table>
            <tr><th>Model</th><th>CoT Strength</th><th>Best Trigger</th><th>Notes</th></tr>
            <tr><td>GPT-4</td><td>Excellent</td><td>"Think step by step"</td><td>Naturally verbose reasoning; benefits from structure</td></tr>
            <tr><td>Claude 3.5</td><td>Excellent</td><td>"Let's work through this systematically"</td><td>Strong at self-correction; use &lt;thinking&gt; tags</td></tr>
            <tr><td>Gemini Pro</td><td>Good</td><td>"Break this into steps"</td><td>Benefits more from few-shot CoT than zero-shot</td></tr>
            <tr><td>GPT-3.5</td><td>Moderate</td><td>Few-shot required</td><td>Zero-shot CoT less reliable; always use examples</td></tr>
        </table>

        <h2>How AI Prompt Architect Helps</h2>
        <p>AI Prompt Architect's <strong>Generate</strong> workflow automatically structures prompts with appropriate chain-of-thought scaffolding based on the complexity of your task. The <strong>Analyse</strong> workflow evaluates whether your existing prompts would benefit from CoT and recommends the right technique — zero-shot, few-shot, or structured CoT — based on the task type. This eliminates guesswork and ensures you're using the right reasoning strategy for every prompt.</p>
Enter fullscreen mode Exit fullscreen mode

This article was originally published with extended interactive STCO schemas on AI Prompt Architect.

Top comments (0)