AI Glossary

Few-Shot Prompting

Few-shot prompting is a technique where you include a small number of worked examples in a prompt so the AI model copies the pattern, style or format you want.

Definition

Few-shot prompting is a prompt engineering technique in which you show an AI model a handful of examples of the task — typically two to five input-and-output pairs — before asking it to complete a new case. The model infers the pattern from the examples and applies it to the new input. Instead of describing in abstract terms exactly what you want, you demonstrate it.

The idea was popularised by the 2020 OpenAI paper "Language Models are Few-Shot Learners" (Brown et al.), which introduced GPT-3. The researchers showed that a large enough model could perform new tasks — translation, classification, question answering — simply from examples in the prompt, without any retraining. This ability is often called in-context learning: the model learns from the context you provide in that moment, and forgets it when the conversation ends.

Zero-shot, one-shot and few-shot

Modern models are good at zero-shot tasks, so few-shot prompting is not always necessary. It becomes valuable when you need a specific format, a house style, consistent labels, or behaviour on tricky edge cases that are hard to describe in words.

Why few-shot prompting works

Language models are pattern-completion engines. Examples are an extremely clear signal of the pattern you want: the length, tone, structure, vocabulary and level of detail. Describing a tone as "friendly but professional" leaves room for interpretation; showing two emails written in that tone removes most of it. Examples also clarify edge cases — for instance, how to label a comment that is half praise and half complaint.

Example

An HR operations team receives hundreds of free-text answers in an employee engagement survey and wants to tag each comment with a theme and a sentiment so they can spot trends.

A zero-shot prompt produces inconsistent results: sometimes the model invents new themes, sometimes it writes long explanations, and mixed comments get labelled differently each time. The team switches to a few-shot prompt:

"Tag each employee comment with one theme from this list: Workload, Manager, Pay, Growth, Tools, Culture. Then add a sentiment: Positive, Negative or Mixed. Reply in the format Theme | Sentiment.

Comment: My manager gives clear feedback every week. → Manager | Positive

Comment: The new laptop is great but the VPN drops constantly. → Tools | Mixed

Comment: I haven't had a raise in two years despite taking on more work. → Pay | Negative

Comment: There's no clear path to promotion in my team. → Growth | Negative

Now tag this comment: We keep getting new projects without anything being taken off our plate."

The model answers "Workload | Negative" — in exactly the right format, using only the approved themes. Applied across the whole survey, the output is consistent enough to paste into a spreadsheet and chart. The team reviews a random sample of tags to confirm accuracy and removes names and identifying details before processing, in line with their data-privacy rules.

Tips for writing good examples

  1. Make examples representative. Cover the main cases, including at least one tricky or mixed case.
  2. Keep the format identical. The model copies structure exactly, including punctuation.
  3. Vary the content. If all examples are positive, the model may lean positive.
  4. Use real but anonymised data. Realistic examples outperform artificial ones; strip personal data.
  5. Don't overdo it. Two to five strong examples usually beat twenty weak ones and save tokens.
  6. Combine with clear instructions. Examples show the pattern; instructions state the rules.
  7. Save winners as templates. A tested few-shot prompt is a reusable team asset.

Limits

Few-shot prompting cannot teach a model knowledge it lacks, and examples consume part of the context window. Models can also overfit to surface features of examples, such as always choosing the label that appeared last. For very high-volume or specialised tasks, organisations sometimes move from few-shot prompting to fine-tuning, but for most everyday work a well-chosen set of examples is the fastest, cheapest way to get consistent output.

Key takeaways

How this relates to our AI course

Few-shot prompting is one of the advanced techniques taught after the CRAFT basics in the AI POWERED course: you learn to add examples to lock in tone and format for emails, reports and data tagging. The prompt library included with the course is full of tested templates that use this technique, ready to adapt to your role.

Browse the prompt library →

Related terms

← All glossary terms