Back to guides
2
5 min

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:

  • The task is common (summarization, classification, translation)
  • The categories are self-explanatory
  • You don't need a specific output format
  • Zero-shot fails when:

  • The task requires domain-specific knowledge ("classify by our internal ticket categories")
  • The output format matters ("return exactly this JSON schema")
  • Edge cases exist that the model might not anticipate
  • 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?

    CountWhen to Use
    1-2Simple tasks, clear categories
    3-5Ambiguous tasks, subtle distinctions
    5-10Complex 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

    ScenarioUse
    Well-known task, flexible outputZero-shot
    Custom categories or labelsFew-shot
    Specific output format requiredFew-shot
    Quick prototype or explorationZero-shot
    Production pipeline with consistency needsFew-shot

    Practice Tasks

    Try these with the sample data in your project:

  • Zero-shot classification: Classify the emails in data/emails.json as urgent/normal/low-priority
  • Few-shot extraction: Extract sender name, company, and intent from each email using 2-3 examples
  • Few-shot generation: Write professional reply suggestions using example replies as style guides
  • Key Takeaways

  • Zero-shot is fast and works for common tasks. Start here, then add examples if quality is low.
  • Few-shot teaches by example — great for custom formats, domain labels, and consistent output.
  • Include edge cases in your examples (nulls, ambiguous inputs) to handle them gracefully.
  • 3-5 examples is the sweet spot for most tasks.
  • 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