Zero-Shot and Few-Shot Prompting
How do you get a model to answer in exactly your format, every time? Navika wants to sort her shop's customer messages into three folders: DELIVERY, REFUND and PRODUCT. When she simply asks, the model returns a different style of label for each message. Then she shows it three examples, and every answer comes back in the same, tidy format.
That is the difference between zero-shot and few-shot prompting.
Zero-Shot and Few-Shot
Zero-shot prompting gives the task with no examples. Few-shot prompting includes a few examples of inputs and the outputs you want, then the new input.
Both answers in the picture are right, but only the few-shot one is usable: a thousand messages labeled DELIVERY, REFUND or PRODUCT can be counted in seconds.
The Few-Shot Prompt in Full
Sort each customer message into DELIVERY, REFUND or PRODUCT. Reply with the label only.
"Where is my order?" -> DELIVERY
"I want my money back." -> REFUND
"The lamp arrived broken." -> PRODUCT
"My parcel still hasn't arrived after ten days." ->Ending the prompt with the arrow invites the model to continue the pattern with just a label.
Choosing Examples
| Do | Why |
|---|---|
| Cover every category | The model sees all the allowed answers |
| Use realistic inputs | Examples should look like your real data |
| Vary them | Different wording keeps the model from copying one phrasing |
| Keep them correct | The model copies mistakes in examples too |
| Keep it short | Two to five examples is usually enough |
Common Mistakes
Examples that all look the same. The model may learn the wrong pattern, such as "short messages are always REFUND".
Mistakes in the examples. The model treats them as correct.
Too many examples. They cost tokens and rarely help beyond a handful.
Interview Corner
What is the difference between zero-shot and few-shot prompting?
Zero-shot gives the task with no examples. Few-shot includes a few input-output examples before the new input, which helps the model match a format or a judgment consistently.
When is few-shot prompting most useful?
When the answer must follow a specific format or labeling scheme, such as fixed categories, or when the task is unusual enough that a description alone is ambiguous.
Practice
Exercise: build a few-shot classifier. Choose a sorting task from your life, such as emails into URGENT, LATER and IGNORE. Write a zero-shot prompt and try it on five real examples. Then write a few-shot version with three examples and try the same five. How many answers changed, and were they more consistent?
Check your understanding:
- What is the "shot" in few-shot?
- Why did the few-shot answer in the picture work better?
- Name three rules for choosing examples.
Key Takeaways
Quick reference
| Term | Meaning |
|---|---|
| Zero-shot | A prompt with no examples |
| One-shot | A prompt with one example |
| Few-shot | A prompt with a few examples |
Was this tutorial helpful?