T1 · Beginner · 7 minStable · Last reviewed: 2026-08-19Early draft

Few-Shot — Teach by Example

In one line · Instead of explaining what you want, give the model a few worked examples (input and output) and it imitates the pattern.

Glossary:Context WindowLLMPromptToken
Why it matters

Some things are hard to describe in words but easy to show. Examples lock in the format and tone far better than any description — provided they're clean and consistent, because the model imitates whatever's in them, warts and all; a sloppy example teaches the wrong thing.

Like showing a new hire 3 messages and how we replied before, then saying 'continue in the same style'. Examples save a whole lecture.

An analogy

Zero-shot means 'get it from the description'; few-shot means 'watch and imitate'. The second is sharper when the exact shape matters.

Want to rewrite sentences formally? Give two examples: 'wanna → I would like to' and 'gonna → I am going to', then add the new sentence and let it continue.

How it works

The model was trained to continue patterns, so when the prompt holds a few (input → output) pairs in the exact same shape and the last pair is left open, it completes it in that pattern. All of this happens in-context inside the context window — no training or fine-tuning takes place. Usually 2-5 varied examples are enough, and consistency of the example format matters far more than their count.

Rewrite the sentence formally.

Input: wanna grab lunch?
Output: Would you like to have lunch?

Input: gonna be late, sry
Output: I will be late, my apologies.

Input: can u send the file?
Output:

Note the last line is deliberately left open — the model completes the pattern. And the format (Input: / Output:) is identical down to the character in every example.

Practice

🧪 Try it yourself: take a classification prompt of yours running zero-shot with shaky results. Add 3 real, consistently-formatted examples (make one an edge case), run the same inputs through both versions, and compare consistency — not just right vs wrong.

Common mistakes
  • Inconsistent examples (one JSON, one free text) — the model imitates the inconsistency itself.
  • All examples are easy cases, so the first real edge case falls over; include at least one hard example.
  • Piling on 15+ examples — burning tokens, cost, and latency for negligible gains, while the model sometimes copies superficial quirks of the examples.
When to use it

When the shape, tone, or classification boundary is hard to describe but easy to show: custom formats, a specific voice, categories with fuzzy edges.

When NOT to use it

If a plain description works, zero-shot is cheaper and faster. And don't use examples to 'teach new logic' — they lock in shape and pattern; they don't grant reasoning ability the model lacked.

LET'S BUILD ITDone reading — now build it yourself.Turn a zero-shot prompt into few-shot