Few-Shot Examples Done Right
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
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
- Cover the variety, especially the edge cases you care about. If a category is rare or tricky, include it.
- Keep examples consistent in format — 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 live input.
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.
:::tip Examples are data — keep them clean A wrong or sloppy example actively teaches the wrong thing. Curate them like training data. :::