Prompting and practice · Read 7 min

Few-shot: teach the AI with examples instead of instructions

Sometimes explaining the task is hard, but showing two examples makes everything clear. AI learns the way we do: by watching.

Think about the last time you tried to teach someone something and words just fell short. You were explaining how to fold a napkin, how to greet people in a meeting, how to strike the right tone in an email, and the other person still didn't get it. Until you did one simple thing: "here, like this." You did it once in front of them and suddenly it clicked. That, carried over to a prompt, is what few-shot prompting is: teaching the AI with two or three examples instead of a long instruction.

The word "shot" here means "example," "demonstration." When you give none and only describe the task, that is zero-shot (zero examples). When you give it a few worked examples before asking for yours, that is few-shot (a handful of examples). You didn't change the model, you didn't retrain it: you simply placed samples inside the same message.

01 · the ideaShow instead of explain

Some tasks are easy to describe and some are easy to show. "Translate this into English" is described in three words and works with no examples. But "classify these comments using my judgment, not yours" is almost impossible to explain in the abstract. Where does "neutral" end and "annoyed" begin? You know it when you see it, but you can't put it into words. That is where showing wins.

With few-shot, instead of drafting a rulebook, you paste in examples you've already solved yourself. The model looks at the pattern (what goes in, what comes out, in what format) and continues the series with your new case. It isn't "learning" in the sense of storing anything for tomorrow: it is recognizing the pattern you placed in front of it and completing it. That is why it's sometimes called in-context learning: the learning happens inside the prompt and is forgotten once it ends.

One well-chosen example is worth more than a paragraph of instructions.

Figure 1 · zero-shot vs. few-shot, side by side
Zero-shot Classify the sentiment: "The shipment arrived late" → ? No examples. The model guesses your judgment and format. Few-shot "Flawless service" → positive "They never replied" → negative "The shipment arrived late" → ? Two examples fix the judgment and format. The third imitates them.
The same new case ("The shipment arrived late") with and without examples. On the right, the two worked examples tell the model both what to decide and in what format to answer.

02 · the practiceHow a few-shot prompt is built

The recipe is simpler than it sounds. A few-shot prompt has three parts: a short instruction, a few example pairs (input → output) and, at the end, your new unsolved input, so the model completes it. Look at this template for classifying the tone of customer messages:

Template of a prompt with examples

Classify the tone of each message as complaint, question or thanks.
"What time are you open until today?" → question
"I've been waiting three days and nobody answers" → complaint
"Thanks, everything arrived perfectly" → thanks
"I was charged twice for the same order" → ______

The model sees three examples with the same shape and, when it reaches the fourth, fills in "complaint" quite naturally. There's no need to explain what a complaint is: it inferred that from the pattern. And something just as valuable: it learned your output format. You asked for a single lowercase word, and that's what it will hand back, not a paragraph explaining its decision.

That control over format is, in practice, the most common reason to use few-shot. If you're going to process the answer with a program (drop it into a table, into JSON, into a spreadsheet), you need it to always come out looking the same. Describing the format in words is fragile; showing three identical outputs pins it down far better.

The idea shot to fame in 2020 with a paper by Tom Brown and his team, whose title says it all: Language Models are Few-Shot Learners [1]. There they showed that a sufficiently large model, with just a few demonstrations in the prompt, could solve tasks it had never been specifically trained on. No weights were adjusted and nothing was retrained: the examples inside the message were enough. That finding is the one you use without a second thought every time you paste a couple of samples before your question.

03 · the judgmentWhen to give examples and when not to

Few-shot isn't always better. It carries a real cost: every example you paste takes up tokens, which means it counts toward the bill and toward the model's context limit. Three short examples weigh nothing; twenty long ones do. So the question isn't "should I add examples?" but "does this task need them?".

The table below sums up when it tends to be worth it and when you're spending too much.

Table 1 · when few-shot beats zero-shot
SituationBetter approachWhy
Common, well-named task (translate, summarize)Zero-shotThe model has seen it a thousand times in training; the example is redundant.
Strict output format (JSON, one word, table)Few-shotExamples fix the exact shape better than describing it.
Your own, fuzzy criterion ("my" tone, "my" category)Few-shotYou show your judgment through cases; no need to explain it in the abstract.
Edge or ambiguous cases you want handled "this way"Few-shotAn example of the odd case tells it what to do when in doubt.
Very limited context or a tight budgetZero-shotEvery example burns tokens; if the task is simple, it doesn't pay off.

Source: synthesis based on OpenAI's guide to prompting strategies [2] and the open OpenAI Cookbook / Prompt Engineering Guide [3].

Two commonsense tips when choosing your examples. First, make them representative: if your real cases include messages with typos, include one with typos; otherwise the model is caught off guard when one shows up. Second, mind the balance: if the four examples you put in are all "complaint", the model may pick up the habit of answering "complaint" to everything. Vary the categories and, if order matters, mix them.

Examples aren't decoration on the prompt: they're the part that teaches.

There's one case where few-shot becomes especially powerful, and that is when you combine it with step-by-step reasoning. If your examples show not only the final answer but also the reasoning that leads to it, the model learns to reason that way before responding. But that's already another technique that deserves its own entry.

For now, hold on to the essentials: when explaining is hard, show. Paste two or three examples you've solved yourself, leave yours blank at the end and let the model continue the pattern. It's the most human way to teach a machine: the very way someone once taught you, simply by saying "here, like this".

Fuentes

  1. Brown, T. et al. (2020). Language Models are Few-Shot Learners. Advances in Neural Information Processing Systems (NeurIPS) 33. arXiv:2005.14165. (Introduces in-context learning with few examples.)
  2. OpenAI. Prompt engineering: Strategy: Provide examples. OpenAI Platform Documentation. platform.openai.com/docs/guides/prompt-engineering.
  3. DAIR.AI. Few-Shot Prompting. Prompt Engineering Guide. promptingguide.ai/techniques/fewshot.

Learn more about AI

See all Learn AI