AI ENGINEERING · PROMPTING AND STRUCTURED OUTPUT · PROMPTING · 8 OF 35

Few-Shot Prompting, Chain of Thought and Reasoning Models

How examples and reasoning change what a model does: zero-shot versus few-shot with three examples steering a classifier, picking diverse examples and the biases their order creates, chain of thought for multi-step problems, reasoning models and their cost and latency, self-consistency voting, when to skip reasoning, and keeping reasoning out of the answer.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
1 / 19

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Few balanced examples
  • watch order bias
  • steps before answer
  • reason only when hard
  • vote
  • hide the thinking

Notes

The idea

Start with two words you will hear constantly. Zero shot means you describe the task and send the input, with no examples. Few shot means you add a handful of worked examples, pairs of input and the output you want, before the real input. Models are extremely good at continuing a pattern. Showing two or three examples often communicates more than a paragraph of rules, especially about format, labels and edge cases.

Zero-shot vs few-shot
  • zero-shot describe the task, send the input, no examples
  • few-shot the same, plus 2 to 5 input and output pairs that show what good means
  • the model copies the pattern

Zero-shot

Here is a zero shot classifier. Label each support ticket as billing, bug or account. The ticket says the app crashed during checkout and I was charged twice. Run it three times. You get payment issue, which is not one of the labels, then bug, then bug slash billing, which is two. Nobody told it the rule for tickets that are both a crash and a money problem.

Zero-shot classifier
Classify the ticket as one of:
billing, bug, account.

Ticket: "The app crashed during
checkout and I was charged twice."

run 1: Payment issue   (not a label)
run 2: bug
run 3: Bug / billing   (two labels)

Few-shot

Now add three examples. A card charged with no receipt, labelled billing. An export button that does nothing, labelled bug. And the hard one, an app that crashed and charged twice, labelled billing, because money comes first. Then the new ticket, followed by the word label and a colon. Now every run returns a single lowercase label, billing. The examples taught the exact format and, more importantly, the rule for the borderline case.

Three examples
Ticket: "Card charged, no receipt"
Label: billing
Ticket: "Export button does nothing"
Label: bug
Ticket: "Crashed and charged me 2x"
Label: billing

Ticket: "{new ticket}"
Label:

Why it works

This is called in context learning. Nothing is trained and no weights change. The examples are simply more tokens in the prompt, and the model continues the pattern they set. Research suggests examples mostly teach the format, the allowed labels and what inputs look like, more than a brand new skill. The price is tokens: every example is sent on every call.

In-context learning
  • no training, no weight
  • updates: the examples are just tokens in the prompt
  • they teach mostly:
  • the output format
  • the set of labels
  • what inputs look like
  • where the boundaries are
  • cost: tokens on every call

Choosing examples

How do you choose examples? Cover every label at least once, roughly balanced. Vary them in length, tone and wording, so the model does not latch on to a surface detail. Use real, messy inputs from production, not tidy textbook ones. Spend your examples on the boundary cases you actually get wrong. Keep the format identical, and wrap them in example tags so the model never mistakes them for the real input.

Good example sets
  • cover every label at least once, roughly balanced
  • vary length, tone, wording
  • real inputs, not tidy textbook ones
  • include the hard boundary cases you actually fail on
  • identical format every time
  • label them in tags so they are not mistaken for input

Order and bias

Examples also bring bias. If all three examples are billing, borderline tickets drift toward billing. That is majority label bias. The last example tends to pull a little harder than the others, which is recency bias. And the model copies surface features, so if every example answer is short, its answers get short too. The fixes are simple: balance the labels, vary the details, shuffle the order, and check your eval score with two or three different orders.

Biases examples create
  • majority bias 3 of 3 examples say billing → borderline tickets drift to billing
  • recency bias the last example's label gets a small extra pull
  • surface copying every example is short → answers get short too

Chain of thought

Now reasoning. Thirty pull requests are waiting. Three people each review four a day, and six new ones arrive daily. How many days to clear the queue? Forced to answer at once, a model often says three days, dividing thirty by twelve and forgetting the new arrivals. Let it work step by step first. Twelve reviewed a day. Minus six new, a net of six. Thirty divided by six is five days. Writing the steps is chain of thought.

A multi-step question
30 PRs wait for review. 3 people
review 4 each per day. 6 new PRs
arrive daily. Days to clear?

answer at once:  "3 days"   wrong

step by step:
  reviewed per day  3 x 4 = 12
  net per day       12 - 6 = 6
  days              30 / 6 = 5

Why it helps

Why does this work? A model spends roughly the same amount of computation on each token it produces. Asked for the answer straight away, it gets one shot at the whole problem. When it writes the steps, each step is small and easy, and every later token can read the intermediate results already on the page. The written steps act as working memory. That is why chain of thought helps most on maths, logic, planning and multi-step code questions.

Why writing steps works
  • a model spends roughly the same compute on every token
  • one-token answer: one shot
  • at the whole problem
  • written steps: each step is easy, and later tokens can
  • read earlier results
  • helps: maths, logic, plans

Prompting for it

To get chain of thought from an ordinary model, ask for it. The simplest form is one line: think step by step. Better, ask for the reasoning inside thinking tags and the final result inside answer tags, so your code can separate them. Order matters. If the answer comes first, the reasoning that follows only justifies a guess already made. Few shot examples can also show worked steps, not just answers.

Reasoning, then answer
Work through the problem step
by step inside <thinking> tags.
Then give only the final result
inside <answer> tags.

order matters:
  answer first → the "reasoning"
  just justifies a guess

few-shot CoT: examples that
show worked steps, not just answers

Reasoning models

Reasoning models build this in. They are trained, often with reinforcement learning, to produce a long stretch of thinking before the answer: planning, trying an approach, checking it and backtracking. You usually control it with an effort level or a thinking token budget. Those thinking tokens are billed as output, and the raw text is often hidden or summarised. With these models, describe the goal and the constraints clearly, rather than scripting every step yourself.

Reasoning models
  • trained, often with reinforce- ment learning, to reason at length before answering
  • you set an effort level or a thinking token budget
  • thinking is billed as output
  • often hidden or summarised
  • give the goal, not a script of steps to follow

Cost and latency

Here is the trade off in numbers. A direct answer of two hundred tokens. The same answer after three thousand tokens of thinking is three thousand two hundred output tokens. At about a hundred tokens per second, that is roughly two seconds versus thirty two seconds, and sixteen times the output cost. On a hard bug or a contract review that is a bargain. On a dropdown suggestion that must appear instantly, it is a broken feature.

One answer, two ways
                 direct   reasoning
thinking tokens       0       3,000
answer tokens       200         200
output total        200       3,200

at ~100 tokens per second:
  time             ~2 s       ~32 s
  output cost        1x         16x

worth it only if accuracy pays

Self-consistency

Self consistency adds another trick. Ask the same question five times with some randomness, say temperature zero point seven, so each run reasons a little differently. Extract only the final answers: five, five, three, five, six. Take the majority, five, with three of five agreeing. Wrong paths tend to scatter while right ones converge. It costs about five times the tokens, though the calls run in parallel, and low agreement is a good signal to send the case to a person.

Sample and vote
  • ask the same question 5
  • times at temperature ~0.7
  • final answers: 5 5 3 5 6
  • majority: 5 (3 of 5 agree)
  • needs one short answer you can compare exactly
  • costs ~5x tokens, but the calls run in parallel
  • low agreement = flag it

When not to reason

Reasoning is not free, so do not use it everywhere. Looking up the refund window, extracting fields from an invoice, simple classification, rewriting and translation gain little from thinking, and on easy tasks a model can even overthink and talk itself out of the obvious answer. A common pattern is routing: a small fast model handles most requests, and only the hard ones go to a reasoning model.

Skip reasoning for
  • lookups: "what is the refund window?"
  • extracting fields
  • simple classification
  • rewriting, translating
  • anything under ~1 s
  • route instead: a small fast
  • model for easy requests, a reasoning one for hard ones

Hide the reasoning

Keep the reasoning out of what users see. Your code extracts the answer tag and shows only that. The scratchpad can contain wrong first attempts, mention internal rules or data, and ramble in ways that confuse people. Reasoning models usually return thinking in a separate block, so simply do not render it. Do log it for debugging. But do not present it as a faithful explanation, because written reasoning does not always match what truly drove the answer.

Keep reasoning internal
  • users get the answer, not the scratchpad, because it
  • may hold:
  • wrong first attempts
  • internal rules or data
  • odd, rambling text
  • log it for debugging
  • do not treat it as a faithful explanation

Common mistakes

The usual mistakes. Examples that all share one label, or are near copies of each other. Reusing eval cases as examples, which makes your scores look better than reality. Asking for the answer before the reasoning. Turning reasoning on for every call. Showing raw thinking to users. And voting on long free form text, where no two answers match exactly.

Common mistakes
  • all examples from one label
  • examples nearly identical to each other
  • test inputs reused as examples, so evals lie
  • asking for the answer before the reasoning
  • reasoning on every call
  • showing users raw thinking
  • voting on free-form text

Numbers worth knowing

Some ballparks. Two to five examples is the usual range, and gains beyond five to ten are often small. One example is typically fifty to three hundred tokens. Reasoning can use anywhere from a few hundred to tens of thousands of thinking tokens per answer, so seconds to a minute or more. Self consistency usually samples three to ten times. Since examples are identical on every call, put them early so prompt caching can reuse them.

Ballpark numbers
few-shot examples     ~2-5, often 3
gains beyond ~5-10    usually small
one example           ~50-300 tokens
thinking per answer   ~hundreds to
                      tens of thousands
reasoning latency     ~5-60 s, more
self-consistency      ~3-10 samples
output vs input       ~3-5x price

cache the examples: same every call

Say it like this

How to say it. Zero shot scored seventy eight percent on our eval set. Three balanced examples, chosen from boundary cases we were failing, raised it to ninety one. Easy requests go to a small fast model. Only hard ones go to a reasoning model with a capped budget, and we parse out the answer tag so thinking never reaches users. High stakes cases vote over five samples. That shows you weigh accuracy against cost and latency.

In the interview
  • "Zero-shot got 78% on our eval; three balanced few-shot examples aimed at boundary cases got 91%. Only hard requests go to a reasoning model, with an answer tag we parse, so thinking never reaches users. High-stakes cases vote over 5 samples."

Interview questions

Q1What is the difference between zero-shot and few-shot prompting?

Zero-shot gives only instructions and the input. Few-shot also includes a handful of input and output examples, which shows the model the exact format, the allowed labels and how to handle borderline cases.

Q2Does few-shot prompting train the model?

No. It is in-context learning: the examples are tokens in the prompt and no weights change. The effect lasts only for that call, and the examples cost tokens every time they are sent.

Q3How do you choose few-shot examples?

Cover every label in a roughly balanced way, vary length and wording, use real production inputs, spend examples on the boundary cases you get wrong, keep the format identical, and never reuse eval cases as examples.

Q4What biases can few-shot examples introduce?

Majority label bias (over-predicting the label most examples share), recency bias (extra pull from the last example) and surface copying of length or style. Balance labels, vary the examples, shuffle the order and test several orders on the eval set.

Q5Why does chain-of-thought prompting improve accuracy?

A model spends roughly fixed compute per token, so a direct answer gets one shot at the whole problem. Writing intermediate steps breaks the problem into easy pieces and lets later tokens build on earlier results, which helps most on multi-step maths, logic and planning.

Q6What is a reasoning model and what does it cost?

A model trained to produce a long thinking phase before its answer, usually controlled by an effort level or token budget. Thinking tokens are billed as output and add latency, often turning a two-second answer into tens of seconds, so it suits hard problems rather than every request.

Q7What is self-consistency?

Sampling several reasoning paths at a non-zero temperature, extracting each final answer and taking the majority. It improves accuracy on problems with a short, comparable answer, costs several times the tokens, and its agreement rate is a useful confidence signal.

Q8Should you show the model's reasoning to users?

Usually not. Ask for the answer in its own tag or use the provider's separate thinking block, show only the answer, and log the reasoning for debugging. The reasoning can contain wrong attempts or internal details, and it is not guaranteed to be a faithful explanation.