Few-Shot Prompting
Few-shot prompting means including 2–5 input/output examples in the prompt before asking the model to do the task.
Introduction
Few-shot prompting means including 2–5 input/output examples in the prompt before asking the model to do the task. It's astonishingly effective — often turning a struggling zero-shot prompt into a reliable one with no fine-tuning required.
Beginner analogy: Showing the intern two completed reports and saying 'now do this one in the same style' — they nail the format every time.
Understanding the topic
Core concepts to understand:
- Provide 2–5 input → output examples that match your real input.
- Examples teach format, tone, edge cases — implicitly.
- Costs more tokens than zero-shot, but improves consistency dramatically.
- Pick diverse examples; don't include only easy cases.
Syntax reference
Visual workflow / architecture:
Few-shot prompt:Q: 2 + 2 → A: 4Q: 5 * 3 → A: 15Q: 10 - 7 → A: 3Q: 8 / 2 → A: ?▼4
Real-world use
Production classifiers, structured-data extractors and code transformers almost always use few-shot. Tools like DSPy and Promptfoo automate few-shot example selection.
Best practices
- Include 3–5 diverse examples covering edge cases.
- Keep examples short — they consume context window.
- Match example format exactly to expected output.
Common mistakes
- Putting only easy examples → model fails on edge cases.
- Too many examples → context overflow + higher cost.
Hands-on exercise
Interview preparation — practice these questions:
- Q1. What is few-shot prompting?
- Q2. How many examples should you include?
- Q3. When does few-shot beat fine-tuning?