Home » Prompt Engineering » Few-Shot Examples

Few-Shot Prompting: Using Examples for Better AI Results

Few-shot prompting means including 2-5 worked examples of the input/output format you expect before giving the AI your actual input. The model learns the pattern from your examples and applies it to new data. This technique is essential when your task has nuances that are difficult to describe in rules but easy to demonstrate through examples, such as tone classification, subjective categorization, or domain-specific formatting.

Why Examples Work Better Than Instructions Alone

Language is inherently ambiguous. When you write "classify this email as urgent or not urgent," every person reading that instruction would apply slightly different criteria for what counts as urgent. The AI model has the same problem: without examples showing your specific threshold, it applies its own interpretation, which rarely matches yours.

Examples eliminate ambiguity by showing rather than telling. Instead of trying to define "urgent" in words, you show three examples of emails you consider urgent and three you consider not urgent. The model identifies the pattern: maybe urgency in your context means revenue impact above $1,000, or mentions of a deadline within 24 hours, or specific words like "production down." Examples communicate these patterns more reliably than prose descriptions.

Research consistently shows that few-shot prompting improves accuracy by 10-30% over zero-shot prompting on tasks with subjective boundaries. For straightforward tasks with clear-cut criteria, zero-shot works fine. For anything where reasonable people might disagree about the correct output, few-shot dramatically reduces errors.

When to Use Few-Shot vs Zero-Shot

Use zero-shot (no examples) when:

Use few-shot (2-5 examples) when:

How Many Examples You Need

The research and practical experience converge on clear guidelines:

2 examples: Sufficient for binary classification (yes/no, pass/fail) where each example represents one class. Also enough for simple formatting tasks where you just need to show the output structure.

3-5 examples: The sweet spot for multi-class classification (3-8 categories). Include at least one example from the most commonly confused categories. If "billing" and "account" are frequently mixed up, include an example of each that makes the boundary clear.

5-8 examples: Needed for complex tasks with many categories or when precision is critical. Also useful when examples need to demonstrate varying input lengths, formats, or edge cases.

More than 8: Rarely helps and significantly increases token costs. If you need more than 8 examples to achieve acceptable accuracy, the task might be better served by fine-tuning or by breaking it into smaller sub-tasks that each need fewer examples.

How to Choose the Right Examples

Cover the Category Boundaries

The most important examples are the ones that demonstrate the boundary between similar categories. If you have 5 categories but two of them are frequently confused (say "technical issue" and "product feedback"), your examples should include one clear case of each that makes the distinction obvious. Obvious, easy examples add little value because the model would get those right without examples. Border cases are where examples earn their token cost.

Vary Input Characteristics

Include examples with different lengths, writing styles, and levels of formality. If all your examples are perfectly written professional emails, the model might fail on poorly written messages, messages with typos, or very short messages. Show the model the range of inputs it will actually encounter. Include a short input, a long input, a formal one, and a casual one.

Include the Most Common Failure Mode

If your zero-shot prompt consistently misclassifies a particular type of input, add that exact type of input as an example with the correct output. This directly teaches the model what you want for the cases it finds difficult. Keep track of errors during testing and add the most common error patterns as examples.

Balance Your Examples

If you have 5 categories and 5 examples, include one from each category. If some categories are rare, still include them because the model needs to know they exist. Imbalanced examples (4 examples of category A, 1 of category B) can bias the model toward the over-represented category.

Example Format: The Input/Output Pattern

Structure your examples consistently using clear delimiters between the input and the expected output. The model identifies this pattern and applies it to the final input you provide. The most common format uses labeled sections:

Example 1:
Input: "Hi, I got charged twice for my subscription this month. Can you fix this?"
Output: {"category": "billing", "urgency": "medium", "action": "route_billing_team"}

Example 2:
Input: "Your app crashes every time I try to upload a file larger than 10MB on Android."
Output: {"category": "technical_bug", "urgency": "high", "action": "route_engineering"}

Example 3:
Input: "It would be great if you could add dark mode to the mobile app."
Output: {"category": "feature_request", "urgency": "low", "action": "log_feedback"}

Now classify this:
Input: [actual user message]

This pattern works because it establishes a clear contract: for any input matching this format, produce output matching that format. The model generalizes from the specific examples to handle inputs it has never seen.

Common Mistakes in Few-Shot Prompting

Examples That Are Too Similar

If all your examples are nearly identical in length, tone, and complexity, the model learns a narrow pattern. When it encounters a different style of input, accuracy drops. Diversify your examples to cover the actual range of inputs you expect.

Incorrect Labels in Examples

A single example with the wrong output teaches the model the wrong pattern. Double-check every example label before deploying. A "billing" complaint mislabeled as "technical" in your examples will cause the model to misclassify similar inputs consistently.

Examples That Contradict Your Rules

If your instructions say "classify messages under 10 words as unclear" but your examples include a 5-word message classified as "billing," the model will follow the example over the instruction. Examples carry more weight than prose rules because they are concrete demonstrations of desired behavior.

Too Many Examples for Simple Tasks

Adding examples to tasks where zero-shot works well wastes tokens without improving results. If your zero-shot prompt already achieves 95%+ accuracy, adding examples likely will not improve it and will increase cost per request. Test zero-shot first, add examples only if accuracy is below your threshold.

Dynamic Few-Shot Selection

For production systems processing diverse inputs, the most advanced technique is selecting examples dynamically based on the current input. Instead of using the same static examples for every request, you maintain a library of 50-100 labeled examples and select the 3-5 most similar to the current input.

This works because example relevance matters: an example of a billing complaint is more helpful when the current input is a billing complaint than when it is a technical question. Similarity can be measured by keyword overlap, embedding similarity, or category prediction from a fast first-pass classifier.

Dynamic few-shot selection is the production version of few-shot prompting. It produces the highest accuracy because the model always sees examples most relevant to its current task. The tradeoff is engineering complexity: you need to maintain an example library, implement a selection mechanism, and ensure selected examples are diverse even within the similarity constraint.

Few-Shot for Style and Tone Matching

Beyond classification, few-shot examples are powerful for teaching the AI your brand's writing style. Include 3-5 examples of responses written in your voice, and the model will match the tone, vocabulary, sentence length, and personality for new responses.

For customer service responses, include examples showing: how you greet customers, how you acknowledge problems, how you phrase solutions, and how you close conversations. For content generation, include examples of your headings style, paragraph length preferences, and how you balance technical detail with accessibility. The AI picks up on patterns you might not even articulate explicitly: whether you use contractions, how formal your punctuation is, whether you address the reader directly. See Prompt Engineering for Content Generation.