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.
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.