Zero-Shot and Few-Shot Prompting
Understanding Prompting Strategies
Not all prompts are structured the same way. Two foundational prompting strategies that every AI Automation Engineer should understand are zero-shot prompting and few-shot prompting. The difference between them lies in whether you include examples in your prompt.
Understanding when to use each strategy -- and why -- directly affects the reliability and quality of the AI outputs you build your systems on.
Zero-Shot Prompting
Zero-shot prompting means giving the model a task with no examples. You simply describe what you want, and the model attempts to complete it based entirely on its training.
The term "zero-shot" comes from machine learning terminology, where "shots" refer to examples. Zero shots means zero examples.
When Zero-Shot Works Well
Zero-shot prompting works reliably for:
- Tasks the model has clearly seen during training (translation, summarisation, common classification tasks)
- Straightforward, well-defined requests
- Situations where generating examples would take more time than the task itself
Zero-Shot Example
Prompt: "Classify the sentiment of the following customer review as Positive, Negative, or Neutral: 'The product arrived on time and works exactly as described. Very happy with my purchase.'"
Output: "Positive"
For a well-defined task like sentiment classification, zero-shot works perfectly. The model understands what sentiment classification is and the three categories are clear.
When Zero-Shot Fails
Zero-shot struggles when:
- The task requires a very specific output format the model cannot infer
- The classification categories are unusual or domain-specific
- The model needs to understand your business logic or a particular style
Few-Shot Prompting
Few-shot prompting means providing examples of the task before asking the model to complete it. You show the model two to five input-output pairs that demonstrate exactly what you want, then give it a new input.
The model learns the pattern from your examples and applies it to the new input. This is sometimes called "in-context learning" because the model learns from examples within the context window of the prompt itself -- no retraining required.
Why Few-Shot Works
LLMs are pattern-matching systems at their core. When you give them clear examples of what you expect, they can identify the pattern and replicate it precisely. Few-shot prompting is one of the most effective techniques for:
- Getting output in a very specific format
- Teaching the model domain-specific terminology
- Ensuring consistent style and structure across outputs
- Handling classification tasks with unusual categories
Few-Shot Example: Ticket Classification
System Prompt: "You classify customer support tickets into categories."
Prompt:
Here are examples of how to classify tickets:
Ticket: "I cannot log into my account and I have tried resetting my password twice."
Category: ACCOUNT_ACCESS
Ticket: "I was charged twice for my subscription this month."
Category: BILLING_ERROR
Ticket: "The mobile app keeps crashing when I try to view my dashboard."
Category: TECHNICAL_BUG
Ticket: "How do I export my data to a CSV file?"
Category: FEATURE_QUESTION
Now classify this ticket:
Ticket: "My account shows a balance of zero even though I deposited money yesterday."
Category:
Output: "ACCOUNT_BALANCE_ISSUE" or the model picks the closest match like "BILLING_ERROR".
By providing four examples, you teach the model the format (all caps, underscore-separated), the categories available, and the style of classification. The model now has a clear pattern to follow.
How Many Examples Should You Use?
Research and practical experience suggest:
| Shots | When to Use |
|---|---|
| 0 (zero-shot) | Standard tasks with clear definitions |
| 1 (one-shot) | When you need to establish format |
| 2-3 (few-shot) | Custom classification, unusual formats |
| 4-6 (few-shot) | Complex tasks with multiple edge cases |
| 7+ | Rarely needed; may hurt performance by filling context |
More examples is not always better. After about five to six examples, you typically see diminishing returns, and very large prompts can actually confuse the model.
Choosing Good Examples for Few-Shot Prompts
The quality of your examples matters more than the quantity. Good examples:
- Cover the range of cases -- include examples of different categories or styles you want the model to handle
- Are unambiguous -- each example should clearly represent one category or style
- Match the real inputs -- use examples similar in length, format, and complexity to the inputs your system will receive in production
- Include edge cases -- if you know certain inputs are tricky, include examples that demonstrate how to handle them
Poor Example Selection
If you are building a content moderation system with four categories but all five of your examples show only one category, the model will be biased toward that category.
Good Example Selection
Balance your examples across the categories your system needs to handle.
Combining Zero-Shot and Few-Shot
In practice, you often use a combination:
- The system prompt sets the role and context (zero-shot style)
- A few examples demonstrate the exact format and edge cases (few-shot style)
- The user prompt sends the actual input
Professional tip: Start with zero-shot. If the output quality is insufficient, add one or two examples. If it is still not meeting your bar, add more examples or refine their quality.
Real-World Application: Email Routing System
Consider an AI system that routes incoming emails to the right team. Here is how the prompting strategy evolves:
Zero-Shot Attempt: "Route this email to one of these teams: Sales, Support, or Finance. Email: 'We are interested in your enterprise plan pricing.'"
This works but might occasionally misclassify ambiguous emails.
Few-Shot Improvement: Add examples:
- "I want to upgrade to the Pro plan" -> Sales
- "My invoice shows the wrong amount" -> Finance
- "The feature is not working as expected" -> Support
With three examples, the model better understands your routing logic, especially for ambiguous cases where "I want to upgrade" could be either a Sales or Support query.
Practice Exercise
Design a few-shot prompt for one of these tasks:
- Classify product reviews by star rating (1-5) based on sentiment
- Extract action items from meeting notes
- Categorise job postings by seniority level (junior, mid, senior)
Write your examples, then test with edge cases to see if the pattern holds.
Key Takeaways
- Zero-shot prompting gives the model no examples and works well for standard, well-defined tasks.
- Few-shot prompting includes two to six examples that teach the model your specific format, style, and categories.
- Few-shot prompting is especially powerful for custom classification, specific output formats, and domain-specific tasks.
- Example quality matters more than quantity -- choose examples that cover the range of inputs your system will encounter.
- Start with zero-shot and add examples only if output quality falls short of your requirements.
Try it yourself
Key Takeaways
- Zero-shot prompting provides no examples and works well for standard tasks the model understands from training.
- Few-shot prompting provides two to six examples that teach the model your specific format, categories, or style.
- In-context learning allows models to adapt to patterns from examples in the prompt without any retraining.
- Example quality and diversity matters more than quantity -- choose examples that cover the range of real inputs.
- Start with zero-shot and only add examples if the output quality is insufficient for your use case.
Quick Quiz
1.What does 'zero-shot' mean in the context of prompting?
2.When is few-shot prompting particularly valuable?
3.How many few-shot examples typically produce the best results?
4.What is 'in-context learning' in the context of few-shot prompting?
Ready to go further?
CareerEx gives you structured 12-week training, live classes every Saturday and Sunday, real tutor feedback, and a certificate. Join the next cohort.
Join CareerEx