Chain-of-Thought and Task Decomposition

Give the model room to reason, and split big jobs into a chain of focused prompts that are easier to control and debug.

Intermediate · about 3 hours · difficulty 3/5

Learn first: Few-Shot Examples, Reasoning Models and Thinking Budgets

Models reason better when they can work through a problem in text before committing to an answer. Chain-of-thought (CoT) prompting asks for that explicitly.

Techniques

  • Think then answer: ask the model to reason inside a <thinking> section and give the final answer in an <answer> section, so your code can extract just the answer.
  • Guided steps: list the steps you want ("first identify the entities, then check each against the policy...").
  • Use reasoning models where available instead of hand-built CoT; they do this natively and you mostly need clear goals.

Prompt chaining

A single giant prompt that researches, drafts, critiques and formats is hard to debug. Split it:

  1. Extract relevant facts.
  2. Draft an answer from those facts.
  3. Check the draft against rules or sources.
  4. Format for output.

Each step has a narrow prompt, a testable output and can use a different (cheaper) model. This is the simplest form of a workflow, which you will build on in the agents section.

Pitfalls

CoT adds output tokens and latency; skip it for easy tasks. The written reasoning is not a faithful explanation of what the model "really" computed, so do not rely on it as an audit trail.

Good enough to move on

You can show a task where CoT or chaining measurably improves accuracy, and you can parse the final answer out reliably.

Key concepts

  • Think-then-answer prompting
  • Guided step-by-step instructions
  • Prompt chaining
  • Self-critique and revision steps
  • Self-consistency (majority vote)

Mini project

Turn a one-shot 'write a cover letter from this resume and job post' prompt into a three-step chain (extract matching skills, draft, critique and revise), and compare outputs side by side.

Check yourself

When is splitting a task into a chain of prompts better than a single prompt with chain-of-thought?

Free resources