What is few-shot prompting?
Few-shot prompting involves including one or more examples in your prompt to demonstrate the pattern, style, format, or approach you want the AI to follow.The term “few-shot” refers to the number of examples:
- Zero-shot: No examples (just instructions)
- One-shot: One example
- Few-shot: Multiple examples (typically 2-5)
- Many-shot: Many examples (6+)
Why few-shot prompting works
Examples are often more precise than descriptions. Consider these approaches:- Zero-shot (instructions only)
- Few-shot (with examples)
Basic few-shot structure
Single example (one-shot)
Use one example for simple pattern demonstration:Multiple examples (few-shot)
Use 2-5 examples for complex patterns:Few-shot prompting by use case
Code generation
Demonstrate coding style, structure, and conventions:Data transformation
Show the exact transformation pattern:Content writing
Demonstrate tone, style, and structure:Test case generation
Show test structure and coverage patterns:Advanced few-shot techniques
Progressive complexity
Start with simple examples and increase complexity:Contrastive examples
Show both correct and incorrect patterns:Domain-specific examples
Provide examples using domain terminology:Few-shot with structured prompts
Combine few-shot learning with structured techniques:Optimizing example quality
1
Use diverse examples
Cover different variations and edge cases in your examples to show the full range of expected patterns.
2
Keep examples realistic
Use realistic, production-quality examples rather than overly simplified ones.
3
Annotate when helpful
Add comments or explanations to examples when the pattern might not be obvious:
4
Balance quantity vs. quality
2-3 high-quality examples usually work better than 10 mediocre ones. More examples aren’t always better.
When to use few-shot prompting
✅ Ideal use cases
✅ Ideal use cases
- Generating code in a specific style or framework
- Data transformation with consistent formatting
- Content creation matching a particular tone
- Test case generation with consistent structure
- API responses following a standard format
- Documentation with specific templates
- Naming conventions and style guides
⚠️ May not be necessary
⚠️ May not be necessary
- Well-known standard formats (JSON, CSV)
- Common programming tasks with clear conventions
- Simple, straightforward requests
- When zero-shot instructions are sufficient
Token efficiency considerations
Examples consume tokens. Balance thoroughness with efficiency:Combining with other techniques
Few-shot prompting works well with other approaches:- Few-shot + Chain-of-thought
- Few-shot + Role-based
Saving and reusing examples
Next steps
Custom instructions
Save few-shot patterns for reuse
Structured techniques
Combine with structured prompting
Create assistants
Build assistants with embedded examples
Token optimization
Manage example token usage

