Few-Shot Learning
Few-shot prompting provides multiple examples to establish patterns, handle variations, and improve consistency. It's one of the most powerful prompt engineering techniques.
What is Few-Shot?
Multiple examples establish the classification rules through pattern recognition.
Why Few-Shot Works
- Pattern Recognition - AI identifies rules from examples
- Disambiguation - Multiple examples clarify edge cases
- Consistency - Output format stays uniform
- Reduced Instructions - Show, don't tell
Few-Shot vs Zero-Shot vs Chain-of-Thought
Few-shot is one of three common approaches. Here is how it compares to zero-shot and chain-of-thought prompting at a glance.
Zero-shot vs few-shot vs chain-of-thought
| Criteria | Zero-shot | Few-shot | Chain-of-thought |
|---|---|---|---|
| Best for | Standard tasks the model already knows | Matching a specific format or style | Multi-step reasoning and harder problems |
| Setup cost | Lowest: instruction only | Medium: write a few good examples | Medium: ask for step-by-step reasoning |
| When to use | Speed matters and the task is common | Output must follow your examples | Answers need to be worked out, not recalled |
| Main limitation | Weak on domain-specific or unusual formats | Examples add length and can bias the output | Longer responses cost more and run slower |
Zero-shot
- Best for
- Standard tasks the model already knows
- Setup cost
- Lowest: instruction only
- When to use
- Speed matters and the task is common
- Main limitation
- Weak on domain-specific or unusual formats
Few-shot
- Best for
- Matching a specific format or style
- Setup cost
- Medium: write a few good examples
- When to use
- Output must follow your examples
- Main limitation
- Examples add length and can bias the output
Chain-of-thought
- Best for
- Multi-step reasoning and harder problems
- Setup cost
- Medium: ask for step-by-step reasoning
- When to use
- Answers need to be worked out, not recalled
- Main limitation
- Longer responses cost more and run slower
Optimal Number of Examples
| Task Complexity | Recommended Examples |
|---|---|
| Simple | 2-3 |
| Moderate | 3-5 |
| Complex | 5-8 |
| Highly nuanced | 8-12 |
More isn't always better - examples use tokens and can cause overfitting.
Exercise: Create Few-Shot Classification
Few-Shot Example Selection
Diversity
Cover different categories and edge cases:
Balance
Don't over-represent one category:
Difficulty Range
Include easy and harder cases:
Few-Shot for Format Consistency
The examples establish:
- Headline - Description format
- Specific benefit language
- Hyphen separator
- Action-oriented copy
Exercise: Few-Shot for Tone
Few-Shot Anti-Patterns
Inconsistent Formats
Too Similar Examples
Misleading Examples
Including incorrect or ambiguous classifications confuses the AI.
Few-Shot for Complex Tasks
For multi-step tasks, show the complete process:
Practice: Building Example Sets
Few-shot learning lets you teach the AI your specific requirements through demonstration rather than explanation.

