Zero-Shot and Few-Shot Prompting

Updated · 4 min read
easyPython 3.13aipromptsfew-shotzero-shotprompt-engineeringinterview

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.

Examples show the model exactly what you want back

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

text
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

DoWhy
Cover every categoryThe model sees all the allowed answers
Use realistic inputsExamples should look like your real data
Vary themDifferent wording keeps the model from copying one phrasing
Keep them correctThe model copies mistakes in examples too
Keep it shortTwo 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:

  1. What is the "shot" in few-shot?
  2. Why did the few-shot answer in the picture work better?
  3. Name three rules for choosing examples.

Quick check: zero-shot and few-shot

4 questions
1What is a few-shot prompt?
2Why use few-shot prompting?
3What happens if an example in the prompt is wrong?
4The model's labels are correct but in different styles. What should you try first?

Key Takeaways

Quick reference

TermMeaning
Zero-shotA prompt with no examples
One-shotA prompt with one example
Few-shotA prompt with a few examples

Was this tutorial helpful?

Lesson 36 of 186