Back to course overview
Module 3Few-shot & chain-of-thought 12 min

Chain-of-thought prompting

Asking for reasoning before the answer: when it genuinely improves accuracy, when it's waste, and how to structure it so software can strip it.

Models generate token by token, and each token gets a fixed slice of computation. Force an instant verdict and complex logic must happen in one hop; let the model write out intermediate reasoning first and the conclusion gets to condition on that reasoning. That's chain-of-thought (CoT) — not a magic phrase, a compute budget.

Where CoT actually pays

  • Multi-rule decisions — 'damage outranks return language, but this email has damage in a quoted forwarded message, does the rule apply?' Reasoning space lets rules interact correctly.
  • Arithmetic and multi-step extraction — totals across line items, date math, 'which of these 14 orders qualifies'.
  • Anything where you need to audit the why. The written reasoning is a debugging artifact: when the answer is wrong, you can see which step went wrong — a misread fact, a misapplied rule — and fix that specifically.

Where it's waste

Simple lookups, style transforms, and easy classifications don't improve — you pay more tokens and more latency for a slower identical answer, and occasionally a worse one when the model talks itself out of an easy call. And a caveat for the current era: reasoning-class models already deliberate internally before answering; explicit 'think step by step' adds less there, though structured reasoning fields are still valuable for the audit trail.

Structure it or suffer

The rookie version — 'think step by step' — produces reasoning smeared through the answer, which breaks every parser you built in Module 2. The engineered version puts reasoning in the schema:

triage-output-with-reasoning.txttext
Return ONLY JSON:
{
  "reasoning": string,   // 2-4 short steps: facts found → rules applied → decision
  "category": ...,        // (rest of schema unchanged)
}
// reasoning comes FIRST so later fields condition on it.
// Software logs `reasoning` and strips it before display.
  • Field order matters. Reasoning must be generated before the verdict fields to help them — JSON fields are produced in the order written.
  • Cap it ('2–4 short steps') or you'll pay for essays.
  • Never show raw reasoning to end users — it's a debug artifact with a different quality bar than your polished output.
Prompt to try

Run your triage prompt on this email twice — once with the reasoning field, once without: "Forwarding my sister's email below about her cracked vase — anyway, my own question: do you ship to Canada? — Original message: 'my vase arrived cracked, order HL-2001'". Compare categories and read the reasoning. Whose complaint is it, and did the reasoning catch that?

A genuinely hard case: damage exists but belongs to a forwarded third party. CoT usually surfaces the distinction; instant classification usually doesn't. This email goes straight into your eval set in Module 5.