Zero-Shot & Few-Shot
Just Ask vs. Show Examples
Zero-Shot: Just Ask
The simplest prompting technique: describe what you want and let the model figure it out. No examples, no special formatting — just a clear instruction.
Classify this email as "urgent", "normal", or "low-priority":
Subject: Server down - all production APIs failing
Body: Our main API server went offline at 3:42 AM. Customer-facing services are returning 500 errors. Engineering is investigating.Zero-shot works well when:
Zero-shot fails when:
Few-Shot: Show, Don't Tell
Instead of explaining what you want, show examples of input → output pairs. The model pattern-matches against your examples.
Classify these emails by department:
Email: "Can I upgrade my plan to enterprise?"
Department: Sales
Email: "The export button isn't working in Chrome"
Department: Support
Email: "We'd like to schedule a demo for our team"
Department: Sales
Email: "Invoice #4521 has the wrong billing address"
Department: ???The model sees the pattern and predicts "Billing" or "Finance" — without you ever defining what departments exist.
How Many Examples?
| Count | When to Use |
|---|---|
| 1-2 | Simple tasks, clear categories |
| 3-5 | Ambiguous tasks, subtle distinctions |
| 5-10 | Complex formatting, domain-specific output |
More examples aren't always better. After 5-7 examples, you get diminishing returns and waste context window space.
Few-Shot for Extraction
Extract contact information from these emails:
Email: "Hi, I'm Sarah Chen from Acme Corp. Reach me at sarah@acme.com or 555-0123."
Result: {"name": "Sarah Chen", "company": "Acme Corp", "email": "sarah@acme.com", "phone": "555-0123"}
Email: "This is Mike at GlobalTech (mike.r@globaltech.io). Our billing address is 123 Main St."
Result: {"name": "Mike", "company": "GlobalTech", "email": "mike.r@globaltech.io", "phone": null}
Email: "Please contact our procurement team at procurement@wayne.co for next steps."
Result: ???Notice the second example includes a null for phone — this teaches the model how to handle missing fields.
Few-Shot for Generation
Write a one-line product tagline in our brand voice:
Product: Project management tool for remote teams
Tagline: "Ship projects, not status updates."
Product: AI-powered email assistant
Tagline: "Your inbox, minus the busywork."
Product: Cybersecurity training platform
Tagline: ???The examples establish tone, length, and style — the model continues the pattern.
Choosing Between Zero-Shot and Few-Shot
| Scenario | Use |
|---|---|
| Well-known task, flexible output | Zero-shot |
| Custom categories or labels | Few-shot |
| Specific output format required | Few-shot |
| Quick prototype or exploration | Zero-shot |
| Production pipeline with consistency needs | Few-shot |
Practice Tasks
Try these with the sample data in your project:
data/emails.json as urgent/normal/low-priorityKey Takeaways
This is chapter 2 of Prompt Engineering Essentials.
Get the full hands-on course — free during early access. Build the complete system. Your projects become your portfolio.
View course details