Few-shot Prompting
Teaching format and edge cases with examples in-context instead of fine-tuning.
In plain words
You show the model a few solved examples first, so it copies the pattern for the new one.
Think of it like…
Showing a new employee three correctly filled forms instead of reading them the manual: they spot the pattern quickly, including how to handle the awkward cases the manual forgot, but if all three examples happen to be "approved", they may start approving everything.
Where you’ve seen it
A support-ticket router has instructions for 12 categories and still mislabels refund versus billing questions. Adding 8 examples (including 3 deliberately tricky ones with a one-line reason) lifts accuracy on a 500-ticket test set from 81 to 92 percent, with no training. Moving to dynamic selection, where the 8 most similar past tickets are retrieved per request, gains a few more points.
Words you’ll hear
- In-context learning
- The model adapts to a task from examples in the prompt, without weight updates.
- Exemplar
- One example input-output pair shown in the prompt.
- Format lock
- Using examples to force an exact output structure.
- Dynamic few-shot
- Retrieving the most relevant examples per request instead of using a fixed set.
Visual diagram
Theory & deep dive
Choosing and formatting examples
Pick examples that cover each output class or format variation, include hard and borderline cases (not only easy ones), and keep them consistent in format, because the model will imitate that format closely. Three to eight well-chosen examples usually capture most of the gain; returns diminish after that and tokens add up. Mark examples clearly, for instance with input and output tags, so the real input at the end is unambiguous.
Watch for biases the examples introduce: if most examples are one label the model leans toward it, and the last example has outsized influence (recency). Balance labels, shuffle order when testing, and avoid examples that leak the answer through superficial patterns. For reasoning tasks, include the reasoning steps in the examples (few-shot chain-of-thought) so the model reproduces the process, not just the answer.
"Ticket: 'I was charged twice and want my money back.' → Label: refund (reason: asks for money back, even though billing is mentioned). Ticket: 'Why is my invoice higher this month?' → Label: billing. Ticket: {new ticket} → Label:"
Dynamic examples and when to fine-tune instead
Dynamic few-shot stores a library of labelled examples, embeds them, and at request time retrieves the k most similar to the new input. This puts the most relevant guidance in front of the model and scales to hundreds of examples, and it's a natural place to add new corrections from production: each mistake you fix becomes a new example.
Few-shot has limits. Long example blocks raise cost and latency on every call (mitigated by prompt caching when the examples are static), and context space is finite. If you need thousands of examples' worth of behaviour, a very stable style, or the lowest latency at high volume, fine-tuning moves that knowledge into weights and shortens prompts. A common path is: zero-shot, then few-shot, then retrieval-based examples, then fine-tune once you have enough data.
When reviewers flag a wrong label in production, add the ticket and its correct label to the example library. Dynamic retrieval then shows it to the model the next time a similar ticket appears, with no deployment.
How it works, step by step
Step 1 of 41. Start with a clear instruction
Measure zero-shot accuracy on a small labelled set so you know what examples must improve.
- Eval set
- fixed
When to use it & trade-offs
What it is
Few-shot prompting puts a handful of worked input-output examples in the prompt so the model infers the task, format and edge-case rules from them, which is in-context learning: no weights change. Zero-shot gives only instructions; one-shot gives one example. Examples are especially good at locking an exact output format and showing how to handle ambiguous cases that are hard to describe in words.
Why it matters: Examples are often the quickest way to fix a model that understands the task but produces the wrong shape, tone or label set. They are cheaper and faster to iterate than fine-tuning, and a few good examples can beat a page of instructions. They also cost tokens on every call and can bias the model, so choosing, ordering and testing them matters.
When to reach for it
- Classification and routing with specific label sets
- Forcing an exact JSON or text format
- Showing how to handle ambiguous or borderline cases
When to avoid or be careful
- Examples that are all easy or all the same label
- Inconsistent example formats
- Dozens of static examples sent on every call without caching
Zero-shot vs few-shot vs fine-tuning
Strengths: Shortest prompt; cheapest.
Watch out: Format and edge-case handling can drift.
Strengths: Fast iteration, no training, easy to add corrections.
Watch out: Tokens on every call; order and label bias.
Strengths: Short prompts; consistent style.
Watch out: Data, training and maintenance effort.
Interview signals & numbers to know
When this topic comes up
- “The model understands but uses the wrong format”
- “How many examples should I include?”
- “It labels everything as the first category”
- Dynamic example selection
- Few-shot vs fine-tuning
Benchmarks & rules of thumb
- 3 – 8
- examples that usually capture most of the benefit
- last example
- has outsized influence (recency)
- +11 points
- the ticket-router example's gain (81 → 92%)
Common mistakes & follow-ups
Common interview mistakes
- Providing five "billing" examples and one "refund" example, then wondering why the model over-predicts billing.
- Letting example formatting vary, so the model's outputs vary the same way.
- Not measuring: judging a prompt from three hand-picked inputs instead of a labelled set.
Likely interviewer follow-ups
- How would you pick examples for a classifier prompt?
- What biases can few-shot examples introduce?
- When would you move from few-shot to fine-tuning?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Few-shot Prompting with generative AI interview Q&A and hands-on practice.