Zero-shot and few-shot: teaching by example
Learn when a plain instruction (zero-shot) is enough and when to show a few examples (few-shot). You'll build a review classifier and a style-matching prompt, and learn how to choose examples that teach the right thing.
Sometimes describing what you want is harder than showing it. Try explaining the exact tone of your college's notice board messages in words, then compare that with simply pasting two old notices. The second works better, for people and for AI.
In this tutorial you will sort customer reviews for the Brew & Bean coffee shop into labels, first with instructions only, then with examples, and see where examples help. You need a free chat tool (ChatGPT, Gemini, Claude or Copilot). Python is optional and only used at the end.
Zero-shot, one-shot, few-shot
The three styles
| Style | What you give | Good for |
|---|---|---|
| Zero-shot | Instructions only, no examples | Common tasks the model already does well: summarise, translate, explain |
| One-shot | Instructions plus one example | Showing a format or a tone once |
| Few-shot | Instructions plus 2-5 examples | Your own labels, edge cases, a house style, a strict output format |
"Shot" just means example. The model does not learn or change permanently from your examples; it uses them as patterns inside this one conversation. Start zero-shot. Add examples only when the answers are inconsistent or don't match what you had in mind.
Step 1: try zero-shot
The workflow in this tutorial
- 1Write a zero-shot prompt with clear instructions and run it on 6 test items.
- 2Note which answers are inconsistent or don't match your rule.
- 3Add 3-5 varied examples that show the rule, including one tricky case.
- 4Run the same test items again and compare.
- 5Save the examples in a script or file so you can reuse them.
Classify each customer review of a coffee shop into one label: taste, price, service or other. Reply with one line per review in the form: number - label.
1. The cold brew was perfect but I waited 25 minutes at the counter.
2. Rs 220 for a cold brew? I can get two filter coffees for that.
3. Banana bread was dry and tasted a day old.
4. Staff remembered my order, so sweet of them.
5. Do you deliver to Koramangala?
6. Great chai, but the price went up again.What to expect: Most models get 3, 4 and 5 right. Reviews 1 and 6 mention two things, so you may get different labels on different runs or tools. That inconsistency is the signal that examples will help.
The problem is not that the model is wrong. Review 6 praises taste and complains about price; both labels are defensible. You have a rule in your head (the owner cares most about the complaint), and the model can't know it. You can write the rule down, but showing it is often clearer.
Step 2: add a few examples
Classify each customer review of a coffee shop into one label: taste, price, service or other. If a review mentions more than one thing, label the complaint, not the praise.
Examples:
Review: Loved the cappuccino, but nobody answered when I called about my order.
Label: service
Review: Croissant was flaky and buttery, worth every rupee.
Label: taste
Review: Nice coffee, but ₹180 is a lot for a student.
Label: price
Review: Is there parking nearby?
Label: other
Now classify these. Reply with one line per review in the form: number - label.
1. The cold brew was perfect but I waited 25 minutes at the counter.
2. Rs 220 for a cold brew? I can get two filter coffees for that.
3. Banana bread was dry and tasted a day old.
4. Staff remembered my order, so sweet of them.
5. Do you deliver to Koramangala?
6. Great chai, but the price went up again.What to expect: Expected: 1 - service, 2 - price, 3 - taste, 4 - service, 5 - other, 6 - price. The examples show the "label the complaint" rule in action, so the mixed reviews 1 and 6 now come out the same way every time.
1 - service
2 - price
3 - taste
4 - service
5 - other
6 - priceStep 3: choose examples that teach the right thing
Models copy everything about your examples, not only the part you meant. If all your examples are short, answers get short. If three of four examples are labelled price, the model leans towards price. If every example is about coffee, it may hesitate on a review about the sandwich.
Good examples are
- Varied: different lengths, items and wording, so the model learns the rule rather than the surface
- Balanced: each label appears, and no label dominates
- Hard where it matters: include at least one tricky case (like mixed praise and complaint) showing your rule
- Consistent: exactly the same format in every example and in the output you expect
- Separate from the real input: not copies of the reviews you are about to classify
- Correct: one wrong example teaches the wrong rule
Examples can mislead the model
If you show only positive reviews as examples, the model may assume most reviews are positive. If your examples all say "Label: price" first and you ask about an ambiguous review, it may pick price because it saw it most recently. When results look biased, check your examples before blaming the model.
Step 4: few-shot for style, not just labels
Examples are just as useful for tone and format. Say Brew & Bean posts a short daily special on WhatsApp and Instagram. Instead of describing the style, paste two past posts.
Write a post in the same style as these examples. Match the length, the structure (item, one sensory line, price, pickup line) and the tone. Do not copy their wording.
Example 1:
Today's pick: Cold Brew. Slow-steeped overnight, smooth and chocolatey. ₹220. Order ahead, pick up in 5 minutes.
Example 2:
Today's pick: Masala Chai. Ginger, cardamom and a proper kick. ₹90. Order ahead, pick up in 5 minutes.
Now write one for: [item name, price, one fact about it].What to expect: A good answer follows the four-part pattern exactly and stays about 20 words. Check that the price matches what you gave and that it didn't reuse "smooth and chocolatey".
How many examples?
Two to five is usually enough. Add another example only when you can name the mistake it will fix. More examples make the prompt longer and slower, and repeating similar examples teaches nothing new.
Step 5 (optional): build a few-shot prompt in Python
If you classify reviews often, keep your examples in one place and generate the prompt. This script does not call any AI; it prints a prompt you can paste into a chat, or later send through an API (covered in *Your first LLM API call* in the AI Engineering track). Save it as build_prompt.py and run it with python build_prompt.py.
EXAMPLES = [
("The cold brew was perfect but I waited 25 minutes at the counter.", "service"),
("Rs 180 for a cappuccino is too much for a student.", "price"),
("Masala chai tasted exactly like home. Loved it.", "taste"),
("Is there parking near the shop?", "other"),
]
new_review = input("Paste a review: ").strip()
lines = [
"Classify a Brew & Bean customer review into exactly one label:",
"taste, price, service or other. Reply with the label only.",
"",
]
for text, label in EXAMPLES:
lines.append(f"Review: {text}")
lines.append(f"Label: {label}")
lines.append("")
lines.append(f"Review: {new_review}")
lines.append("Label:")
print("\n".join(lines))Ending the prompt with "Label:" invites the model to complete just the label, which keeps answers short and easy to read in code.
Paste a review: The banana bread was dry and stale.
Classify a Brew & Bean customer review into exactly one label:
taste, price, service or other. Reply with the label only.
Review: The cold brew was perfect but I waited 25 minutes at the counter.
Label: service
Review: Rs 180 for a cappuccino is too much for a student.
Label: price
Review: Masala chai tasted exactly like home. Loved it.
Label: taste
Review: Is there parking near the shop?
Label: other
Review: The banana bread was dry and stale.
Label:How this comes up in interviews
For AI and data roles, a common question is: "How would you get an LLM to classify support tickets into our categories?" A good answer: start zero-shot with clear label definitions, measure on a small labelled set, add a few varied examples for the categories it confuses, and only consider fine-tuning if prompting can't reach the accuracy you need (compared in *Prompting vs RAG vs fine-tuning* in the AI Engineering track).
Try it: Build your own classifier
Pick a labelling task you care about: sorting college notices (exam, event, fee, holiday), tagging your expenses (food, travel, books, other) or classifying bug reports (UI, crash, performance). Write 10 test items yourself and note the correct label for each. Run zero-shot, count how many are right, then add 3-4 examples and count again.
Key takeaways
- Zero-shot means instructions only; few-shot adds a handful of examples inside the prompt.
- Start zero-shot; add examples when answers are inconsistent or don't match your rule or style.
- Models copy everything about examples: length, format, label balance and wording.
- Choose varied, balanced, correct examples, including one tricky case that shows your rule.
- Two to five examples is usually enough; add one only when you know which mistake it fixes.
- Test on items that are not in your examples.
Check yourself
Finishing the quiz marks the lesson as done.
1. When should you move from a zero-shot prompt to a few-shot prompt?
2. All four of your examples are labelled "positive". What is the most likely effect?
3. What is the main job of the example "Loved the cappuccino, but nobody answered when I called. Label: service" in the lesson?
4. You use 5 reviews as few-shot examples, then measure accuracy on those same 5 reviews. What is wrong?
5. Do few-shot examples permanently train the model?
Saved on this device. Create a free account to keep it on every device.
Practise this with Sam
A real mock interview, out loud, with an honest scorecard. Free to start.