Lesson 2 of 5 · Free to read
Show, don't tell: few-shot examples
Show, don't tell: few-shot examples
Audience: Final-year students and engineers in their first three years
Prerequisites: Lesson 1
Time: about 25 minutes
What you will keep: a tested few-shot prompt for a task you repeat
This lesson does not cover: fine-tuning models.
Why this matters
Some things are easier to show than to describe. Your team's commit message style, the exact shape of a ticket checklist, how you name test cases: you could write a paragraph of rules, or you could paste two good examples. The second usually works better for format and style. Putting examples in a prompt is called few-shot prompting; a prompt with no examples is zero-shot.
When examples help
Examples are strongest when you care about consistency of shape:
- Output format: commit messages, changelog entries, test names, JSON with specific keys.
- House style: tone of release notes, how much detail goes in a ticket.
- Conventions the model cannot guess: your team's labels, prefixes, or ordering.
They help less when the task needs knowledge or reasoning the examples do not show. Two examples of good SQL do not teach the model your database schema; for that you need context, not examples.
A worked example: commit messages
Zero-shot prompt:
"Write a commit message for this diff."
You will get something reasonable, but its style will change every time: sometimes a long paragraph, sometimes a bullet list, sometimes a title in past tense.
Few-shot prompt:
Write a commit message for the diff at the end, in the same style as these examples.
Example diff: adds a null check in parse_date() before calling strptime
Example message:
fix(dates): return None for empty date strings
parse_date() raised TypeError on empty input from the signup form.
Example diff: new endpoint DELETE /tasks/{id} with two tests
Example message:
feat(tasks): add DELETE /tasks/{id}
Returns 204 when deleted and 404 for a missing id.
Diff:
<paste your diff here>
Now the output follows the pattern: a typed title under about 60 characters, a blank line, then one or two sentences on why.
How to choose examples
- Make them consistent with each other. If one example has a body and one does not, the model has to guess which you want.
- Cover the variation you expect. If your real inputs include fixes and features, show one of each.
- Keep them realistic and short. Examples cost space in the prompt and attention for the model.
- Do not let content leak. The model sometimes copies details from the examples into the answer. Use examples whose details clearly do not belong in the real answer, and check for copying.
How many?
Start with two. Add a third if the output still drifts on some kind of input. Beyond a handful, extra examples rarely help much and make the prompt harder to maintain. If you need many examples to get the format right, the instructions are probably unclear; fix those first.
Exercise: zero-shot against few-shot
Pick a task you do at least weekly that has structured output: commit messages, standup notes, ticket checklists or test names.
- Write a zero-shot prompt. Run it on three real inputs and save the outputs.
- Add two consistent examples. Run it on the same three inputs and save the outputs.
- For each pair, note which output you would actually use, and why.
- Check the few-shot outputs for details copied from your examples.
Save the final prompt in your prompt library (lesson 5). Write two sentences on where examples helped and where they did not.
Key points
- Examples teach shape and style better than rules do.
- Use two or three consistent, realistic examples.
- Watch for details copied from the examples into the answer.