Chapter 2: Types of Prompts (Zero-shot, Few-shot)
π― Learning Objectivesβ
After completing this chapter, you will be able to:
- Define and apply zero-shot prompting
- Define and apply few-shot prompting
- Determine when to use each approach
- Create effective examples for few-shot learning
π Introductionβ
One of the most important decisions in prompt engineering is whether to provide examples. This chapter explores the two fundamental approaches: zero-shot (no examples) and few-shot (with examples) prompting.
Understanding the Terminologyβ
Before diving in, let's clarify these terms borrowed from machine learning:
| Term | Meaning in AI | Meaning in Prompting |
|---|---|---|
| Zero-shot | Model performs task without specific training | Prompt without examples |
| One-shot | Model learns from one example | Prompt with one example |
| Few-shot | Model learns from a few examples | Prompt with 2-5+ examples |
Zero-Shot Promptingβ
Zero-shot prompting means asking the AI to perform a task without providing any examples.
How It Worksβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ZERO-SHOT PROMPTING β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β USER: "Translate 'Hello, how are you?' to French" β
β β
β AI relies on: β
β β’ Pre-trained knowledge β
β β’ Understanding of task from instruction β
β β’ No specific examples provided β
β β
β AI: "Bonjour, comment allez-vous ?" β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Zero-Shot Examplesβ
Simple Classification:
Classify the sentiment of this review as positive,
negative, or neutral:
"The product arrived on time but the quality was
disappointing. Won't buy again."
Sentiment:
Text Generation:
Write a professional email declining a job offer
politely while leaving the door open for future
opportunities.
Information Extraction:
Extract the date, time, and location from this text:
"The conference will be held on March 15, 2024,
at 9 AM in the Grand Ballroom of the Hilton Hotel."
When to Use Zero-Shotβ
β Use zero-shot when:
- The task is straightforward and well-defined
- The AI likely has strong pre-trained capabilities for the task
- You want quick results without crafting examples
- The format/style you want is standard
β Avoid zero-shot when:
- The task requires specific formatting
- You need consistency across many outputs
- The task is unusual or domain-specific
- Initial zero-shot results are inconsistent
Few-Shot Promptingβ
Few-shot prompting provides examples that demonstrate the desired input-output pattern.
How It Worksβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FEW-SHOT PROMPTING β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β EXAMPLES PROVIDED: β
β βββββββββββββββββββββββββββββββββββββββββββ β
β β Example 1: Input β Output β β
β β Example 2: Input β Output β β
β β Example 3: Input β Output β β
β βββββββββββββββββββββββββββββββββββββββββββ β
β β
β NEW INPUT: [Your actual task] β
β β
β AI learns the pattern from examples and applies it β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Few-Shot Example: Sentiment Classificationβ
Classify the sentiment of movie reviews.
Review: "This movie was absolutely fantastic! Best film I've seen this year."
Sentiment: Positive
Review: "Terrible acting, boring plot. Complete waste of time."
Sentiment: Negative
Review: "It was okay. Some good parts, some not so good."
Sentiment: Neutral
Review: "The special effects were amazing but the story was predictable."
Sentiment:
Few-Shot Example: Data Extractionβ
Extract product information from descriptions.
Description: "Apple MacBook Pro 14-inch, M3 chip, 16GB RAM, 512GB SSD, Space Gray - $1,999"
Product: MacBook Pro 14-inch
Brand: Apple
Specs: M3 chip, 16GB RAM, 512GB SSD
Color: Space Gray
Price: $1,999
Description: "Samsung Galaxy S24 Ultra, 256GB, Titanium Black, Unlocked - $1,299.99"
Product: Galaxy S24 Ultra
Brand: Samsung
Specs: 256GB, Unlocked
Color: Titanium Black
Price: $1,299.99
Description: "Sony WH-1000XM5 Wireless Noise Canceling Headphones, Silver - $349"
Product:
Brand:
Specs:
Color:
Price:
Few-Shot Example: Custom Formatβ
Convert meeting notes to action items format.
Notes: "John will update the website by Friday. Sarah needs to review the budget proposal. Team should schedule a follow-up meeting next week."
Action Items:
β’ [ ] John: Update website (Due: Friday)
β’ [ ] Sarah: Review budget proposal
β’ [ ] Team: Schedule follow-up meeting (Due: Next week)
---
Notes: "Marketing to prepare Q2 campaign by March 1st. Dev team should fix the login bug ASAP. Lisa will coordinate with the vendor about pricing."
Action Items:
β’ [ ] Marketing: Prepare Q2 campaign (Due: March 1st)
β’ [ ] Dev team: Fix login bug (Priority: ASAP)
β’ [ ] Lisa: Coordinate with vendor about pricing
---
Notes: "Tom needs to finish the report. The design team will create new mockups. We should update clients about the delay."
Action Items:
Comparison: Zero-Shot vs Few-Shotβ
| Aspect | Zero-Shot | Few-Shot |
|---|---|---|
| Examples needed | None | 2-5+ |
| Setup time | Minimal | More effort |
| Consistency | Variable | Higher |
| Token usage | Lower | Higher (examples cost tokens) |
| Best for | Standard tasks | Custom formats, edge cases |
| Learning curve | Lower | Requires good example selection |
Visual Comparisonβ
ZERO-SHOT:
βββββββββββββββββββββββββββββββββββββββ
β Task: Classify sentiment β
β β
β Input: "Great product!" β
β β
β β AI uses general knowledge β
β β
β Output: Positive β
βββββββββββββββββββββββββββββββββββββββ
FEW-SHOT:
βββββββββββββββββββββββββββββββββββββββ
β Task: Classify sentiment β
β β
β Example 1: "Love it!" β Positive β
β Example 2: "Hate it!" β Negative β
β Example 3: "It's fine" β Neutral β
β β
β Input: "Great product!" β
β β
β β AI learns pattern from examples β
β β
β Output: Positive β
βββββββββββββββββββββββββββββββββββββββ
Best Practices for Few-Shot Examplesβ
1. Diversity in Examplesβ
Include examples that cover different scenarios:
β GOOD: Diverse examples
- Positive review (short)
- Negative review (detailed)
- Neutral review (mixed feelings)
β BAD: Homogeneous examples
- Positive review
- Another positive review
- Yet another positive review
2. Consistent Formatβ
Maintain the same structure across all examples:
β GOOD: Consistent format
Input: "text" β Category: [result]
Input: "text" β Category: [result]
Input: "text" β Category: [result]
β BAD: Inconsistent format
Input: "text" β Category: [result]
"text" is: [result]
[result] for "text"
3. Representative Examplesβ
Choose examples that represent real use cases:
β GOOD: Realistic
"The delivery was late but the product quality is excellent" β Mixed
β BAD: Artificial
"Product good. Happy. Buy again." β Positive
4. Clear Delimitersβ
Separate examples clearly:
β GOOD: Clear separation
Example 1:
Input: [text]
Output: [result]
---
Example 2:
Input: [text]
Output: [result]
---
Now process:
Input: [new text]
Output:
How Many Examples?β
| Number | Name | Use Case |
|---|---|---|
| 0 | Zero-shot | Standard, well-defined tasks |
| 1 | One-shot | Simple pattern demonstration |
| 2-3 | Few-shot | Most common for custom tasks |
| 4-5 | Few-shot | Complex or nuanced tasks |
| 6+ | Many-shot | Highly specific patterns |
More examples = more tokens = higher cost. Find the minimum number of examples that achieves consistent results.
Advanced: Chain-of-Thought Few-Shotβ
Combine few-shot with reasoning explanations:
Solve these word problems.
Problem: "A store has 45 apples. They sell 12 and receive a shipment of 30. How many apples do they have?"
Thinking: Start with 45, subtract 12 sold (45-12=33), add 30 received (33+30=63)
Answer: 63 apples
Problem: "If a train travels at 60 mph for 2.5 hours, how far does it go?"
Thinking: Distance = Speed Γ Time, so 60 mph Γ 2.5 hours = 150 miles
Answer: 150 miles
Problem: "A recipe needs 3 cups of flour for 12 cookies. How much flour for 20 cookies?"
Thinking:
Answer:
Practical Exerciseβ
Exercise: Convert Zero-Shot to Few-Shotβ
This zero-shot prompt gives inconsistent results:
Convert these informal messages to professional emails.
Message: "hey can u send me the report asap thx"
Your Task: Create a few-shot version with 2-3 examples that ensures consistent formatting.
View Solution
Convert informal messages to professional emails.
Message: "hey can u send me the report asap thx"
Professional Email:
Subject: Report Request
Dear [Name],
I hope this message finds you well. Could you please
send me the report at your earliest convenience?
Thank you for your assistance.
Best regards,
[Your name]
---
Message: "yo meeting 2morrow is cancelled btw"
Professional Email:
Subject: Meeting Cancellation Notice
Dear Team,
I wanted to inform you that tomorrow's meeting has
been cancelled. I apologize for any inconvenience.
We will reschedule and notify you of the new date.
Best regards,
[Your name]
---
Message: "can someone fix the printer its broken again"
Professional Email:
Subject: Printer Maintenance Request
Dear IT Support,
I am writing to report that the printer in [location]
is not functioning properly. Could someone please
look into this issue? Thank you for your help.
Best regards,
[Your name]
---
Message: "running late to the client call sry"
Professional Email:
Key Takeawaysβ
- Zero-shot prompting works without examples; best for standard tasks
- Few-shot prompting uses examples to demonstrate patterns; best for custom formats
- 2-3 examples are usually sufficient for most tasks
- Examples should be diverse, consistent, and representative
- More examples = higher cost; find the minimum effective number
- Few-shot excels at custom formats, edge cases, and ensuring consistency
What's Next?β
In the next chapter, we'll explore the basic prompt structures that provide frameworks for different types of tasks.
β Previous: Anatomy of a Prompt | Next: Basic Prompt Structures β