Examples are one of the most reliable ways to control format, tone and edge cases, especially for repetitive automation tasks.
Describing what you want is good. Showing it is often better. A prompt with no examples is called zero-shot; a prompt with a few worked examples is few-shot (one example: one-shot).
Suppose an AI step tags support emails. You could describe the tags at length, or you could add:
- "My card was charged twice" ->
billing - "The app crashes when I log in" ->
bug - "Can you add dark mode?" ->
feature-request
The model now knows the exact labels, the format (a single lowercase tag) and where the borderline cases fall.
How to write good examples:
- Make them realistic. They should look like the real inputs, including messy ones.
- Make them varied. If every example is short and polite, the model may learn "short and polite" as part of the pattern. Include an edge case or two, such as an email that fits no tag.
- Keep the format identical in every example: same labels, same separators, same layout. Inconsistencies get copied.
- Separate them clearly from the real input, for example by wrapping each in
<example>tags.
How many? There is no magic number; Anthropic suggests about three to five, and Google recommends experimenting because too many can make the model over-copy them (repeating their wording or length).
Examples and instructions work together. Use instructions for the rules and examples to show what "good" looks like. If the model copies something you did not intend, such as always choosing the label of the last example, vary the order and add a counter-example.
Example
Classify each message as billing, bug, feature-request or other. Reply with the label only.
<example>Message: My card was charged twice this month.
Label: billing</example>
<example>Message: The app freezes when I upload a photo.
Label: bug</example>
<example>Message: Do you have an office in Berlin?
Label: other</example>
Message: Could you add an export to Excel?
Label:Remember
- Few-shot = a few input/output examples inside the prompt
- Examples should be realistic, varied and identically formatted
- Combine rules (instructions) with examples (what good looks like)
Watch out for
- Copying the same example style every time; the model mimics length and tone as well as the label.