Forward-deployed / Learning zone
Prompt engineeringa standalone module
Lesson 05

Few-shot, chain-of-thought, and self-consistency

TL;DR

Three techniques from the research literature reliably lift model quality on tasks that are harder than "reword this paragraph." Few-shot — showing the model a few worked input-output pairs before the real input — lifts consistency on classification, extraction, and any task with a house style words can't fully describe. Chain-of-thought (CoT), from Wei et al. 2022, asks the model to reason step by step before answering, and lifts accuracy on math, logic, and multi-hop reasoning. Self-consistency, from Wang et al. 2022, samples several answers and takes the majority, at the cost of running the same prompt several times. Each has a specific job, a specific cost, and a specific failure mode. Beginner-level prompts often work without them. Anything harder than pattern-matching against training data usually needs one.

🎯 For the AI PM (or coding-agent user)

Why it matters — Modern models often do CoT internally on hard problems (the reasoning-model class does it by default), but you still need to know when the technique earns its cost — and when few-shot gives you a bigger lift than a bigger model.

What it changes in your decisions — Before you upgrade to a more expensive model, you first try three worked examples and step-by-step reasoning. Cheaper, faster, often enough.

Ask yourself — "Have I actually shown this model what the right answer looks like, or have I only described it in words?"

Risk if ignored — You pay for a bigger model to solve a problem a smaller model with three examples would have handled. Or you ship a reasoning-heavy feature that silently fabricates answers when a two-line "think step by step" would have caught the error.

The three techniques

The decision ladder

Start baseline · add technique when the problem earns it

Each technique has a specific job, a specific cost, and a specific failure mode.

Baseline prompt — instructions only
↓ harder problem ↓
Few-shot
+ 1–5 worked examples
Chain-of-thought
+ "think step by step"
↓ stakes justify N calls ↓
Self-consistency — sample N times, take majority answer

Read the diagram as a decision ladder. Start with the baseline prompt. When consistency slips, add few-shot examples. When the problem involves multi-step reasoning, add chain-of-thought. When the stakes justify running the same call several times, add self-consistency on top.

Few-shot: show, don't tell

The pattern is simple. Put 1-5 worked examples between the instructions and the input, each labeled clearly:

<examples>
<example>
<input>Meeting notes: "Team agreed to ship v2 by Q3. Anna will draft the plan by Friday."</input>
<output>{"action_items": [{"owner": "Anna", "task": "draft the plan", "due": "Friday"}]}</output>
</example>
<example>
<input>Meeting notes: "We discussed the roadmap. No decisions."</input>
<output>{"action_items": []}</output>
</example>
</examples>

<input>{{USER_INPUT}}</input>

Three lessons from a decade of use:

Few-shot works because it's a shorthand for a specification that would be tedious to write. The model interpolates between the examples. The right examples define the right interpolation.

Chain-of-thought: reason step by step

Wei et al. showed in 2022 that appending "let's think step by step" to a prompt lifted the model's performance on math word problems by tens of percentage points. The mechanism, roughly: the model is a next-token predictor. When it commits to an answer first, it has no way to backtrack. When it commits to reasoning first, each step in the reasoning constrains the next, and the final answer inherits the constraint.

Two flavours:

A concrete shape:

Think step by step. Show your reasoning. Then give the final answer inside <answer>...</answer>.

The <answer> tag lets the calling code parse just the answer while the reasoning trace is available for debugging and evaluation.

A note on reasoning models. Modern reasoning-tuned models (the OpenAI o-series, Claude's extended-thinking mode, DeepSeek-R1-class open models) do chain-of-thought internally by default. Explicit CoT prompts are less necessary — sometimes counterproductive, since the model has already been trained to reason. The technique still applies to non-reasoning models and to cases where you need the reasoning trace visible.

Self-consistency: sample and vote

Wang et al. (2022) showed that on reasoning tasks, running the same prompt N times with a nonzero temperature, then taking the majority answer, beats a single call — even a single call at the same total token cost. The intuition: the model's "single answer" is one sample from a distribution. Sampling several and voting approximates the mode of the distribution, which is often closer to correct than any one sample.

The cost is real: N calls instead of 1. Reserve self-consistency for:

Don't reach for it on open-ended generation (essays, creative writing) — there's no majority to vote on.

Tradeoffs

Failure modes

Practitioner checklist