Few-shot prompts: show the AI an example row

Words describe what you want; an example shows it. How to add one to three example rows to a prompt for categorising, cleaning or summarising data, and why the AI then follows your pattern instead of its own.

Short answer: a few-shot prompt gives the AI one to three examples of input and the output you want, then the new input. The AI copies the pattern: your categories, your spelling, your format. Use it whenever the answer has to fit something that already exists, like your product categories, your naming rules or your report style. Pick examples that cover the tricky cases, not just the easy ones.

The words say what you want; an example shows it. "Categorise these support tickets" gets the AI's categories. Three tickets with your categories next to them get yours.

What does a few-shot prompt look like?

  1. 1
    The task"Give each ticket one category from our list"
  2. 2
    The listBilling, Login, Bug, Feature request, Other
  3. 3
    Examplesthree tickets with the category you would give them
  4. 4
    New inputthe tickets to categorise
  5. 5
    Format"one line per ticket: ID, category"
A few-shot prompt, in order
Give each support ticket one category: Billing, Login, Bug, Feature request or Other.

Examples:
T-101 "I was charged twice in October" -> Billing
T-102 "Reset link never arrives" -> Login
T-103 "Export to CSV would save me hours" -> Feature request

Now categorise, one line each as ID, category:
T-201 "Can't sign in since the update"
T-202 "Invoice shows the wrong VAT number"

How do you pick good examples?

  • Cover the borders. "Can't sign in since the update" could be Login or Bug. Include an example that shows which way you decide.
  • Use your real format. If the output goes into a table, show the exact columns.
  • Keep them short. Three clear examples beat ten long ones.
  • Vary them. Three billing examples teach the AI that most things are billing.

When does it help most?

JobWithout examplesWith examples
Categorise free textThe AI invents categoriesYour categories, your edge cases
Clean names ("ACME corp.", "Acme Corporation")A different spelling each timeOne canonical form
Write metric definitionsLong, generic paragraphsYour template, your length
Summarise a chart for emailA wall of textThree sentences, in your tone

What goes wrong?

  • Examples that disagree with the instructions. The AI follows the examples.
  • Real customer text. Make the examples up, or remove names and numbers.
  • No check. Categorise 20 rows you already know, and count how many match, before you run the rest.

Where can you check this?

Where do you start?

Start with a job you repeat every week, and save the prompt in a prompt library. For prompts that write queries, see prompt engineering for SQL.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.