Few-Shot Examples Done Right
- What few-shot prompting is and why examples beat descriptions
- How to read a clean few-shot prompt that the model completes
- How to choose, format, and order examples (including edge cases)
- When to reach for zero-shot vs few-shot
- Why a sloppy example is worse than no example
Few-shot prompting means showing the model a few worked examples of the task before asking it to do a new one. Done well, it's the fastest way to lock in a format, style, or edge-case behavior — often better than describing what you want in words.
Why examples beat descriptions
"Be concise and friendly" is vague. Showing two concise, friendly outputs is unambiguous. The model pattern-matches the examples and continues the pattern.
A clean few-shot prompt
Notice the shape: several Message → Label pairs in identical format, then a final message with an empty Label: for the model to fill in.
Few-shot classification prompt
Classify each support message as: billing, bug, or feature. Message: "I was charged twice this month." Label: billing Message: "The app crashes when I upload a photo." Label: bug Message: "Can you add dark mode?" Label: feature Message: "My subscription renewed at the wrong price." Label:
The model has the pattern; it completes the last line.
How to choose and format examples
- Include the edge cases you care about. If a category is rare or tricky, include it.
- Same structure, same labels, same delimiters. Inconsistency teaches inconsistency.
- 2–5 is often enough. More helps for hard/varied tasks but costs tokens and can overfit to the examples' quirks.
- Order can matter — put the clearest examples first; for classification, don't cluster all of one label together.
- Use delimiters (or XML tags) to separate examples from the input you actually want labeled.
The token cost above is real — see Tokens & Context. For the delimiter approach, XML tags are a clean, reliable separator.
Zero-shot vs few-shot
Try zero-shot (just ask) first — modern models are strong. Add examples when you need a specific format/style or the task is ambiguous. If zero-shot already nails it, don't pay for examples.
- Examples are data — keep them clean. A wrong or sloppy example actively teaches the wrong thing. Curate them like training data.
- Show, don't tell: worked examples beat vague descriptions.
- Cover the variety, especially edge cases, and keep every example in an identical format.
- 2–5 examples is usually enough; more can overfit and costs tokens.
- Order matters — clearest first, and don't cluster one label together.
- Start zero-shot; add examples only for specific format/style or ambiguity.