Few-Shot Learning
Teach AI new patterns by showing examples. Master the technique that makes prompts dramatically more reliable.
The Most Powerful Technique
In the previous lesson, we explored roles and personas. Now let’s build on that foundation. If I could teach you only one advanced technique, it would be this one.
Few-shot learning—showing AI examples of what you want—is absurdly effective. It often solves problems that no amount of instruction can fix. It turns inconsistent outputs into reliable ones. It lets you teach AI custom formats, styles, and logic that it wasn’t explicitly trained for.
And most people don’t use it. They write longer instructions instead.
This lesson shows you how to use examples properly.
What Is Few-Shot Learning?
The terminology comes from machine learning:
- Zero-shot: Give instructions only, no examples
- One-shot: Give one example
- Few-shot: Give 2-5 examples
In practice, “few-shot prompting” means including input-output examples that demonstrate the pattern you want.
Zero-shot:
Classify the following customer message as Positive, Negative, or Neutral.
Message: “The product arrived damaged and nobody will help me.”
Few-shot:
Classify customer messages as Positive, Negative, or Neutral.
Examples:
Message: “Love this! Best purchase I’ve made all year.” Classification: Positive
Message: “It’s okay, nothing special but works fine.” Classification: Neutral
Message: “Waited 3 weeks and still no delivery. Horrible.” Classification: Negative
Now classify this message: Message: “The product arrived damaged and nobody will help me.”
The few-shot version is longer but dramatically more reliable. The AI sees the pattern, matches the format, and gives consistent outputs.
Why Examples Beat Instructions
Instructions tell the AI what to do. Examples show it.
And showing beats telling for the same reason it does with humans. When you say “write in a casual tone,” that’s subjective. My casual and your casual might be different.
But when you show three examples of your casual tone? The AI calibrates precisely to what you actually mean.
Examples work because they:
- Reduce ambiguity — No interpretation needed
- Establish format — The AI mimics the structure exactly
- Set tone — Your voice, demonstrated
- Handle edge cases — Show how to handle tricky inputs
The Anatomy of Good Examples
Not all examples help equally. Here’s what makes examples effective:
1. Realistic inputs
Use examples that look like real data you’ll actually process.
Bad: Fake-looking test data
Input: "Test message here"
Output: "Test response"
Good: Realistic representative cases
Input: "Hi, I placed an order #4521 last week but it says pending?"
Output: "Order Status Inquiry - Order #4521 - Priority: Normal"
2. Diverse cases
Show variety to teach the full pattern, not just one case.
If classifying sentiment, include:
- Clearly positive
- Clearly negative
- Ambiguous/neutral
- Mixed (positive and negative elements)
If extracting data, include:
- Complete information present
- Partial information
- Missing required fields
3. Consistent format
Every example should follow the identical format. The AI learns the pattern from consistency.
Bad: Inconsistent formats
Input: "Great product!"
→ Positive sentiment
Message: I hate waiting
Classification = Negative
Good: Consistent structure
Input: "Great product!"
Classification: Positive
Input: "I hate waiting"
Classification: Negative
4. Edge cases
Include at least one example that handles something tricky.
For sentiment analysis, you might show:
Input: "The product is good but the shipping was terrible"
Classification: Mixed
Reasoning: Positive about product, negative about shipping
This teaches the AI what to do when inputs don’t fit cleanly.
How Many Examples?
Quick check: Before moving on, can you recall the key concept we just covered? Try to explain it in your own words before continuing.
The research and practical experience converge on a range:
| Examples | When to Use |
|---|---|
| 1-2 | Simple tasks, format demonstration |
| 3-5 | Most tasks, sweet spot for reliability |
| 6-10 | Complex patterns, many edge cases |
| 10+ | Rarely needed, diminishing returns |
More examples eat context window. After 5-6, you often get better results by improving example quality rather than adding quantity.
Few-Shot Template
Here’s a reliable structure:
[TASK DESCRIPTION]
Brief explanation of what you want.
[EXAMPLES]
---
Input: [example input 1]
Output: [example output 1]
---
Input: [example input 2]
Output: [example output 2]
---
Input: [example input 3]
Output: [example output 3]
---
[ACTUAL REQUEST]
Now process the following:
Input: [your actual input]
Output:
The “Output:” at the end primes the AI to respond in the same format.
Worked Example: Product Categorization
Let’s build a few-shot prompt for categorizing e-commerce products.
Task: Categorize products into departments based on their title.
Starting simple (zero-shot):
Categorize this product into a department: "Sony WH-1000XM5 Wireless Noise Canceling Headphones"
This might work, but returns will vary. “Electronics”? “Audio”? “Headphones”? “Tech”?
Adding examples (few-shot):
Categorize products into the appropriate department.
Available departments: Electronics, Home & Kitchen, Clothing, Sports & Outdoors, Books, Toys & Games
---
Product: "Instant Pot Duo 7-in-1 Electric Pressure Cooker"
Department: Home & Kitchen
Product: "Nike Men's Revolution 6 Running Shoe"
Department: Clothing
Product: "Kindle Paperwhite 16GB E-Reader"
Department: Electronics
Product: "LEGO Star Wars Millennium Falcon Building Set"
Department: Toys & Games
---
Now categorize:
Product: "Sony WH-1000XM5 Wireless Noise Canceling Headphones"
Department:
Now the AI knows exactly what categories to use and how to format the response. Consistent, every time.
Few-Shot for Style and Tone
Examples are especially powerful for capturing voice. Instructions like “sound professional but friendly” are vague. Examples make it concrete.
You're writing customer service responses. Match this style:
---
Customer: "Where's my order?"
Response: "I totally get the wait is frustrating! Let me look that up for you right now. What's your order number?"
Customer: "This product broke after one day"
Response: "Oh no, that's definitely not okay. We'll make this right. Can you send me a quick photo of the issue? I'll get a replacement headed your way ASAP."
Customer: "Do you ship internationally?"
Response: "We do! Shipping times vary by location—usually 7-14 days for international orders. Any specific country you're shipping to?"
---
Now respond to:
Customer: "Can I change my shipping address?"
Response:
The AI now has a concrete model of your voice—casual, helpful, action-oriented. It’ll match that style precisely.
Common Mistakes
Mistake 1: Examples don’t match real inputs Your examples show simple cases, but real inputs are messy. The AI won’t know how to handle the mess.
Mistake 2: Inconsistent formatting between examples The AI learns from patterns. Inconsistency teaches confusion.
Mistake 3: All examples are the same type If every example is a positive case, the AI may struggle with negative ones.
Mistake 4: Examples are too long Long examples eat context. Keep them tight—enough to show the pattern, no more.
Key Takeaways
- Few-shot learning means teaching by example—often more effective than long instructions
- 3-5 examples typically hit the sweet spot between coverage and efficiency
- Good examples are realistic, diverse, consistent, and include edge cases
- Format examples identically—the pattern is what the AI learns
- End with “Output:” to prime the AI to match your format
Up next: chain-of-thought prompting. We’ll teach AI to show its reasoning—and why that dramatically improves accuracy.
Knowledge Check
Complete the quiz above first
Lesson completed!