In this guide
Few-shot prompting means including a small number of worked examples in your prompt, so the model can see the pattern you want and follow it. Instead of describing the format and tone in words, you show it. It is one of the most reliable ways to get consistent output for tasks like classification, rewriting and data extraction.
Zero-shot, one-shot and few-shot
The terms describe how many examples you provide:
- Zero-shot: no examples, only instructions.
- One-shot: a single example.
- Few-shot: a handful of examples, typically two to five.
The model does not retrain when you do this. It reads the examples as part of the prompt and uses them as a guide for the rest of the response. This is often called in-context learning, and it only lasts for that conversation or request.
A first example: classification
Say you want customer messages sorted into categories. A zero-shot prompt might produce labels you did not expect. A few-shot prompt fixes the labels and the format:
Classify each message as Billing, Technical or Other. Reply with the label only.
Message: "I was charged twice this month."
Label: Billing
Message: "The app crashes when I open settings."
Label: Technical
Message: "Do you have an office in Berlin?"
Label: Other
Message: "My invoice shows the wrong company name."
Label:The model now knows the exact label set, the one-word output and the pattern to continue. This is much more dependable than hoping it guesses your categories.
A second example: matching style
Examples are also useful for tone. Suppose you want product descriptions in a particular voice:
Write a product description in the same style as the examples.
Product: Steel water bottle
Description: Keeps drinks cold through a long day. No fuss, no leaks.
Product: Canvas tote bag
Description: Big enough for the market, tough enough for the commute.
Product: Desk lamp
Description:You did not have to define "short, warm, slightly playful". The examples do it for you.
When few-shot prompting helps most
- Fixed output formats, such as a specific table row, JSON shape or email layout.
- Classification and tagging, where labels must be consistent.
- Style matching, when tone is hard to describe.
- Extraction tasks, where you need the same fields every time.
- Edge cases, where you want to show how an unusual input should be handled.
For tasks that depend on step-by-step logic, examples can be combined with reasoning requests. See chain-of-thought prompting.
How to choose good examples
- Make them representative. Cover the typical cases you expect.
- Include variety. If all examples look alike, the model may copy surface details such as length.
- Include a tricky case. Show how to handle ambiguity, such as a message that could fit two labels.
- Keep the format identical. Same labels, same punctuation, same order.
- Make sure they are correct. A wrong example teaches a wrong pattern.
- Balance the labels. If four examples are "Billing" and one is "Other", the model may lean towards "Billing".
Common pitfalls
Copying too closely. The model may reuse phrases or structure from your examples. If outputs look like clones, add more varied examples or tell it to vary wording.
Hidden patterns. If your examples all happen to be short, the model may assume short is required. Check what the examples have in common beyond what you intend.
Order effects. The order of examples can nudge results. If it matters, test a few orders on a small sample.
Wasted space. Examples take up room in the prompt. Each model has a limit on how much it can read at once, explained in what a context window is. Use only as many examples as you need.
Confidential data. Do not paste real customer data as examples unless your policy allows it. Make up realistic ones instead.
Testing your prompt
Treat the prompt like a small experiment. Prepare ten or so test inputs, including awkward ones, and run them. Count the errors, adjust the examples or instructions, and run again. A prompt that works on three inputs may fail on the fourth, so test before using it widely.
Few-shot prompting sits alongside instructions rather than replacing them. Keep a short instruction at the top, as described in how to write good AI prompts, and use examples to remove remaining ambiguity. If you are new to the topic, start with what prompt engineering is. QAM.AI covers examples-based prompting in a text lesson with exercises, and the preview lessons are free to read.
Key takeaways
- Few-shot prompting shows the model a few input and output examples so it can follow the pattern.
- It works best for fixed formats, classification, extraction and style matching.
- Choose accurate, varied examples with an identical format, and include at least one tricky case.
- Test on a set of realistic inputs before relying on the prompt.
- Examples use up space in the prompt, so use only what you need.
Frequently asked questions
How many examples should I include?
Start with two or three and add more only if results are inconsistent. More examples are not always better, because they use space and can introduce unwanted patterns. Test with real inputs to find the point where quality stops improving.
Is few-shot prompting the same as fine-tuning?
No. Few-shot prompting puts examples in the prompt for a single request, and the model itself does not change. Fine-tuning adjusts the model through additional training, which is a separate and more involved process.
Should I still write instructions if I give examples?
Yes. A short instruction states the goal, and the examples clarify details. Together they are more robust than either alone, especially for inputs that do not resemble your examples.
This guide is general educational information and is reviewed periodically. AI tools change quickly, so check each vendor's current documentation before relying on specific features or limits.