bigonotes
AIPrompting

Few-Shot Examples

How to show the model two or three input-output pairs so it copies your format, and how to avoid the ways examples mislead it.

3 min readLast updated

Sometimes telling the model what to do is not enough. Showing it works better. Few-shot prompting means putting two or three examples of the input and output you want directly in the prompt, before the real task. The model sees the pattern and follows it.

When examples help#

Examples shine when a format is hard to describe but easy to show. They also help when the model keeps getting the format slightly wrong even though your instructions are clear.

Two or three examples communicate structure faster and more reliably than a paragraph of description. If your clear instructions still produce the wrong shape, add examples before you add more words.

What a few-shot prompt looks like#

Here is a small prompt that sorts support messages into labels. It has an instruction, three examples and then the real input, with the answer left blank.

Classify each support message as billing, bug or account.
Reply with the label only.

Message: I was charged twice for my March invoice.
Label: billing

Message: The export button does nothing when I click it, and
the page shows a blank screen after about ten seconds.
Label: bug

Message: How do I change the email on my profile?
Label: account

Message: My card was declined but the money still left my bank.
Label:

Notice the variety. The messages differ in length, the three labels each appear once, and the style changes from a plain statement to a question. The model finishes the last line the same way as the ones above it.

A prompt built from an instruction, three varied examples and the real input, with the output left blank

How examples go wrong#

Models copy what they see, including features you did not mean to teach. Each failure below has a matching fix.

Failure What happens Fix
Surface-feature copying If every example is short, the model produces short outputs. Mix lengths and styles.
Label skew If every example has the same label, outputs lean toward that label. Cover every label, and keep the mix balanced.
Last-example weight The last example is closest to the real task, so an edge case there may be treated as the norm. Put a typical case last, and keep edge cases few.
One example is not enough A single pair rarely shows the boundary for nuanced classification. Use two or three, chosen to show the difference between labels.

The weight of the last example comes from how the message list is read: the model processes it in order, and the end of the prompt has the most pull.

How to choose examples#

The fix for all four failures is the same: vary your examples on purpose. Vary the length, the label and the style, and make sure edge cases are not overrepresented.

A useful check is to read your examples as the model would. Ask what they have in common besides the thing you want taught. Anything they all share, such as length, wording or label, is a feature the model may copy.

Short line#

Few-shot prompting shows the model two or three input-output pairs so it copies the pattern. Vary length, labels and style, and keep edge cases from dominating, because models copy surface features and the last example weighs most.

Key takeaways#

  • Few-shot means placing two or three input-output examples in the prompt, before the real task.
  • Use it when a format is hard to describe but easy to show, or when the model keeps getting it slightly wrong.
  • Models copy surface features: length, style and label frequency all leak from your examples into the output.
  • The last example carries extra weight, so do not end on an edge case.
  • One example is often not enough for nuanced classification.
  • Vary lengths, labels and styles deliberately.
Revision notes · 1 min

Core idea#

Few-shot prompting puts two or three input-output examples in the prompt, before the real task. The model sees the pattern and follows it.

Key points#

  • Use examples when a format is hard to describe but easy to show.
  • Use them when the model keeps getting the format slightly wrong despite clear instructions.
  • Two or three examples carry structure faster than a long description.
  • The model copies surface features of your examples.
  • Vary length, label and style on purpose.
  • Keep edge cases few.

Failure modes#

Failure Effect Fix
Surface-feature copying Short examples give short outputs Mix lengths and styles
Label skew Outputs lean toward the repeated label Cover every label in balance
Last-example weight An edge case last becomes the norm End on a typical case
One example only Boundary stays unclear Use two or three

Pitfalls#

  • Do not give examples that all share one label.
  • Do not end the list on an edge case.
  • Do not rely on one example for nuanced classification.

Short line#

  • "Show two or three varied examples before the real task. Models copy surface features, and the last example weighs most."

Found a mistake? Email ask@bigonotes.com