Examples and Few-Shot Prompting
Describing a style or a format in words is hard. Showing it is easy. Examples are one of the most reliable tools in prompting.
Zero-shot, one-shot and few-shot
- Zero-shot: instructions only, with no examples.
- One-shot: one example.
- Few-shot: several examples, typically three to five.
Start zero-shot. Add examples when the output is inconsistent or the format is hard to describe.
A classification example
Zero-shot:
Classify the sentiment of this review as positive, negative or mixed.
Review: The battery lasts all day but the screen scratches easily.
Few-shot:
Classify the sentiment of each review as positive, negative or mixed.
Reply with one word.
Review: Fast delivery and works perfectly.
Sentiment: positive
Review: Stopped working after a week. Waste of money.
Sentiment: negative
Review: Great sound, although the app is confusing.
Sentiment: mixed
Review: The battery lasts all day but the screen scratches easily.
Sentiment:
The examples settle questions the instructions left open: what counts as “mixed”, and that the answer should be a single lowercase word.
Examples for style
Rewrite each product note as a one-line customer benefit.
Note: 4000 mAh battery
Benefit: Lasts a full day on one charge.
Note: IP68 rated
Benefit: Survives rain, spills and a drop in the sink.
Note: 120 Hz display
Benefit:
Three lines of examples convey a tone that would take a paragraph to describe.
Choosing good examples
- Relevant. Use examples that look like the real inputs.
- Varied. Cover different cases, including the awkward ones. If every example is positive, the model leans positive.
- Balanced. For classification, include each label, in mixed order.
- Correct. The model copies mistakes as faithfully as it copies everything else.
- Consistent in format. Use the same labels, spacing and punctuation throughout.
The model copies more than you intend
A model picks up every pattern in your examples, including accidental ones. If all your example answers are about 20 words long, expect 20-word answers. If they all start with “Great”, so will the output. Vary whatever you do not want copied.
Separate examples from the task
Mark clearly where examples end and the real input begins. Tags work well:
Extract the company name and the amount from each invoice line.
<examples>
<example>
Input: Paid Acme Ltd 1,250.00 on 3 March
Output: {"company": "Acme Ltd", "amount": 1250.00}
</example>
<example>
Input: Invoice from Northwind Traders for 89.50
Output: {"company": "Northwind Traders", "amount": 89.50}
</example>
</examples>
Input: Transfer of 4,300 to Blue Yonder Airlines
Output:
When examples are not enough
If the task needs reasoning, not only a pattern, examples of answers alone may not help. Show the reasoning too, or ask the model to reason step by step, which is covered later in this course.
Practice
Write a few-shot prompt that converts informal messages such as “can u send the report asap” into polite, complete sentences. Include three varied examples.