Chapter 6 · Show examples (few-shot)#

The big idea#

Sometimes the easiest way to explain what you want is to show it. A few-shot prompt includes two to five worked examples of input and output before the real input. The model copies the pattern: the labels, the tone, the length and the layout. A prompt with no examples is called zero-shot.

Everyday example: Teaching a new colleague to tag support tickets: you could write a ten-page guide, or you could say “these three went to billing, these two to access, now do this one”. The examples carry rules you never had to write down.

In plain words

Pick examples that cover the different cases, including a tricky one. Keep their format identical to the real input.

A picture#

Show examples Two or three examples teach a pattern faster than a paragraph of rules. Show examples Before Classify this ticket: 'App crashes' After Ticket: 'Charged twice' -> billing Ticket: 'Cannot log in' -> access Ticket: 'App crashes' -> Examples set labels and style Same model, same question. Only the prompt changed.
Two or three examples teach a pattern faster than a paragraph of rules.

Before and after#

Replies below are typical examples to show the difference. Your model will word things differently, so run the prompts yourself.

Example 1 · Classifying tickets#

Before

Classify this support ticket: "App crashes when I open it"

Typical reply

This ticket describes a problem with the application, which appears to be crashing on launch. It might be a technical issue that should be investigated by the engineering team. The category could be a bug or a compatibility problem.

After

Classify each ticket as billing, access or bug. Reply with the label only.

Ticket: "I was charged twice this month" -> billing
Ticket: "I cannot log in after changing my password" -> access
Ticket: "The page goes blank when I click Save" -> bug

Ticket: "App crashes when I open it" ->

Typical reply

bug

Prompt checker (code/promptcheck.py, columns T C A F L E D):

before   1/7  [Y . . . . . .]  missing: context, audience, format, limits, example, delimiters
after    3/7  [Y Y . . Y . .]  missing: audience, format, example, delimiters

Why it works. Without examples the model does not know your labels, so it explains. With three examples it answers in your labels and in one word.

Example 2 · Matching a style#

Before

Write a product tagline for a reusable water bottle.

Typical reply

Introducing the ultimate hydration companion: stay refreshed, stay sustainable, and make every sip count with our eco-friendly reusable water bottle!

After

Write a product tagline in the same style as these examples: short, playful, max 6 words.

Product: noise-cancelling headphones -> Silence, now with bass.
Product: running shoes -> Chase the last kilometre.

Product: reusable water bottle ->

Typical reply

Refill the planet, one sip.

Prompt checker (code/promptcheck.py, columns T C A F L E D):

before   2/7  [Y . Y . . . .]  missing: context, format, limits, example, delimiters
after    4/7  [Y Y . . Y Y .]  missing: audience, format, delimiters

Why it works. Describing a style (“short, playful”) is fuzzy. Two examples pin it down exactly, including length.

How many examples?#

Situation

Examples

Simple label from a short list

2 to 3

A style or tone to copy

2 to 3

Tricky edge cases

Add one example per edge case

Answers keep drifting

Add one example that shows the wrong case being handled

More examples cost tokens (and money) and can make the model copy the examples too closely. Start with two, add only when the answer is wrong.

Order matters. Examples near the end of the list have a slightly stronger pull, so avoid ending on an unusual one.

Rules of thumb#

  • Keep every example in exactly the same layout as the real input.

  • Cover each label at least once and balance them (not three “bug” and one “billing”).

  • End the prompt where the answer should begin (after the arrow).

Common mistakes#

  • Examples that disagree with each other.

  • Only showing easy cases so the hard case gets guessed.

  • Labels in the examples that differ from labels you allow in the instruction.

Try it yourself#

  1. Build a few-shot prompt that turns a city into a country: Paris -> France.

  2. Your classifier always answers “bug”. What do you check first?

  3. When would you not use examples?

Answers
  1. “Name the country. Paris -> France\nTokyo -> Japan\nLima ->” The model should answer Peru.

  2. Whether your examples are balanced. If most examples are “bug” the model leans that way.

  3. When the task is simple and well known, or the examples would be long and expensive for little gain.

Next

Examples show what to do. Constraints say where the edges are. Next: constraints and positive framing.