Few-Shot Prompting: Guiding the AI by Example
Two or three well-chosen examples replace a long paragraph of instructions. How to select them, present them and avoid slavish copying.
Take a restaurant owner who wants to sort his customer reviews to see what comes up most often. He pastes in a review and asks:
Classify this review by theme.
The answer can be right and unusable. On the first review, the AI writes a whole sentence. On the second, it answers "Mixed experience." On the third, it invents yet another category. After twenty reviews, there's nothing you can count.
He could add formatting rules, and that would help. He can also keep it shorter: show two or three reviews already classified the way he wants. That's few-shot prompting, guiding the model with a few examples instead of describing everything. With no examples, it's called zero-shot; with just one, one-shot.
What examples say better than instructions
An instruction describes what you want in words, and words leave wiggle room. "Professional but warm tone" covers dozens of ways of writing. An example settles length, punctuation, level of detail and what to leave out all at once, including things you wouldn't have thought to specify.
It's especially worthwhile in three situations:
- classification, when the categories need to stay stable from one run to the next;
- repeatedly transforming a text into a specific form, like notes into meeting minutes;
- tone, because it's easier to show than to explain.
For an open-ended question, like coming up with name ideas for a company, examples can instead box the model in: it will produce variations on what you showed it. There, save your examples for the end, when you want to refine one lead.
The same review sorting, with three examples
Here's the restaurant owner's corrected prompt. The categories are closed, the format is shown rather than described, and the last example settles an ambiguous case.
You classify restaurant customer reviews for a tracking spreadsheet. Allowed themes: food, service, wait, price, atmosphere, other. Allowed sentiment: positive, negative, mixed. Answer only with one line in the format: theme | sentiment | summary in under 8 words. If the review touches on several themes, keep the one that weighed most in the customer's judgment. Examples: Review: "The duck breast was perfect, cooked just right." Answer: food | positive | duck breast perfectly cooked Review: "Steep bill for portions like that." Answer: price | negative | portions too small for the price Review: "Very good dish, but 40 minutes to get served on a Tuesday lunch, we won't be back." Answer: wait | negative | 40-minute wait, won't return Review to classify: [PASTE THE REVIEW HERE]
The third example does most of the work. It contains a strength and a flaw, and the answer shows how to decide: the customer isn't coming back because of the wait, so the theme is the wait. A rule alone would have left more room for interpretation, and the example makes it concrete.
Choosing examples that cover the hard cases
The common reflex is to pick the clearest examples, the ones the AI would have gotten right without help. They serve the format, but they teach it nothing about how to decide.
An effective selection comes down to three ideas:
- a typical case, to set the format;
- an edge case, the one you yourself hesitated over;
- variety: if all your examples are positive, or all short, the model may lean that way.
The easiest way to find the edge case is to run your prompt without examples on about ten real cases, then spot where it goes wrong. Each error you correct becomes a candidate. It's a way of testing a prompt that improves it at the same time.
How many examples, and in what form
There's no magic number. Two to five examples are enough for many everyday tasks. If your results stay unstable with five, the problem often comes from your categories, which are too close to each other, rather than from a lack of examples.
For presentation, three details matter:
- Keep exactly the same structure in every example. The AI reproduces patterns, including your labels (
Review:,Answer:) and your irregularities. - Clearly separate the examples from the case to handle, with a label like "Review to classify" or tags. Without that, the model may treat an example as a request.
- Pay attention to order. The last example may weigh more: put a nuanced case there rather than an extreme one.
If you want very strict output, combine examples with the techniques for imposing an output format.
When the AI copies your examples
The method's main flaw shows up as soon as you ask for written text: the AI picks up your turns of phrase, your sentence structure, sometimes a detail of substance that has no business being there. A teacher who provides an example containing "needs to participate more in class discussions" risks finding the phrase in half the comments, including for students who speak up very well.
Two remedies: vary the examples clearly from one another, and say explicitly what they're meant to show. This prompt applies both, with anonymized students (don't paste students' personal data into a tool without knowing what your school allows).
You help a middle school teacher write report card comments from her quick notes. The examples below show the length (2 sentences), the tone (direct, kind, no empty phrases) and the structure (a specific observation, then practical advice). Don't reuse their wording: each comment must rely only on the notes provided. Notes: good level, inconsistent work turned in, has forgotten homework since November Comment: Results are solid when the work is done, but the repeated lapses since November are dragging down the average. A planner filled in every evening would be enough to solve the problem. Notes: shy, big progress in writing, doesn't dare ask for help Comment: The progress in writing is clear and rewards serious work. Now it's time to dare to ask questions in class; they'll help everyone. Notes to process for student [INITIAL]: [YOUR QUICK NOTES] If the notes are too thin to write two specific sentences, say so instead of filling in the gaps.
Without the last line, the model may fill the holes with plausible generalities. Still, reread every output, because it can misinterpret a note. When the goal is to reproduce a voice over time, one example is no longer enough and you need to build a profile sheet: that's the subject of the article on getting the AI to write in your style.
Your first example already exists
Find the last AI output you corrected by hand before using it. The corrected version, together with the starting text, makes a ready-to-use example pair. Add it to the prompt, rerun it on a new case and see whether you still need to make the same correction.