Skip to main content

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:

TermMeaning in AIMeaning in Prompting
Zero-shotModel performs task without specific trainingPrompt without examples
One-shotModel learns from one examplePrompt with one example
Few-shotModel learns from a few examplesPrompt 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​

AspectZero-ShotFew-Shot
Examples neededNone2-5+
Setup timeMinimalMore effort
ConsistencyVariableHigher
Token usageLowerHigher (examples cost tokens)
Best forStandard tasksCustom formats, edge cases
Learning curveLowerRequires 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?​

NumberNameUse Case
0Zero-shotStandard, well-defined tasks
1One-shotSimple pattern demonstration
2-3Few-shotMost common for custom tasks
4-5Few-shotComplex or nuanced tasks
6+Many-shotHighly specific patterns
Token Economics

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​

Summary
  1. Zero-shot prompting works without examples; best for standard tasks
  2. Few-shot prompting uses examples to demonstrate patterns; best for custom formats
  3. 2-3 examples are usually sufficient for most tasks
  4. Examples should be diverse, consistent, and representative
  5. More examples = higher cost; find the minimum effective number
  6. 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 β†’