Skip to main content

Few-Shot Examples Done Right

Intermediate
What you'll learn
  • 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

Guided walkthrough1 of 5
  1. Include the edge cases you care about. If a category is rare or tricky, include it.

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.

Pro tip
  • Examples are data — keep them clean. A wrong or sloppy example actively teaches the wrong thing. Curate them like training data.
Key takeaways
  • 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.

Check yourself

0/5
  1. Why do examples often beat a written description like 'be concise and friendly'?
  2. How many examples are 'often enough' for a few-shot prompt?
  3. For a classification task, how should you order examples?
  4. When should you prefer zero-shot over few-shot?
  5. What is the risk of a sloppy or wrong example?

Next