Summary

Chain of Thought (CoT) is a prompting technique that encourages the LLM to break down complex reasoning tasks into a series of intermediate steps. By explicitly showing the model how to "think step by step," it dramatically improves performance on tasks requiring multi-step reasoning like math problems, logical puzzles, and complex decision-making.

Implementation

  1. Use explicit prompting with phrases like "Let's think step by step" or "Let's solve this problem by breaking it down."
  2. Encourage detailed reasoning by asking the model to explain its thought process for each step.
  3. Structure matters - use numbered steps or clear paragraph breaks to help the model organize its thoughts.
  4. For complex problems, consider combining with few-shot examples that demonstrate the desired reasoning pattern.
  5. Request verification by asking the model to check its work after reaching a conclusion.

Common pitfalls

  • Shallow reasoning: Prompt for deeper analysis
  • Skipping steps: Request explicit intermediate steps
  • Wrong format: Provide example structure
  • Premature conclusions: Ask model to verify answer

Best for

  • Mathematical problems requiring step-by-step calculation
  • Logical reasoning tasks with multiple premises
  • Multi-step decision making scenarios
  • Any task where the path to the answer matters as much as the answer itself

Build This Pattern

Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to implement this pattern.

Build me a chain-of-thought prompting system. Architecture: implement a prompt builder that takes a reasoning problem and constructs a prompt with explicit reasoning instructions. The output parser extracts the Reasoning section (numbered steps) and the Answer section using regex or LLM-based extraction. Support both zero-shot CoT (prepend a trigger phrase) and few-shot CoT (dynamically insert 2-3 examples). Include a config flag for which mode to use and an examples library for few-shot mode. Error handling: if the output lacks clear Reasoning or Answer sections, use a second LLM call to reformat. If answer extraction regex fails, fall back to LLM-based extraction. Handle cases where the LLM answers before reasoning by post-processing reorder. Edge cases: handle math problems needing numeric validation against reasoning. Support multi-line reasoning steps. Detect and filter off-topic reasoning steps. Best practices: log reasoning quality metrics (number of steps, reasoning-to-answer ratio). Parse answer section separately from reasoning for downstream use. Make the trigger phrase configurable. Testing: test with math problems, logic puzzles, and multi-step decisions. Verify answer extraction with and without clear section headers. Compare zero-shot versus few-shot output formats. TypeScript.