Few-Shot Prompting: Teaching by Example
Few-shot prompting provides examples directly in the prompt, showing the model exactly what you want rather than just describing it.
Key Takeaways
| Takeaway | Details |
|---|---|
| Example Count | Few-shot typically uses 3-10 examples, with quality mattering more than quantity. |
| In-Context Learning | Models learn new tasks from examples without gradient updates or retraining required. |
| Format Consistency | Examples should use identical formatting and complete, valid structures for pattern matching. |
| Example Ordering | Place most similar examples at the end due to recency bias in model attention. |
| Use Cases | Most valuable for specific output formats, specialized domains, and consistent edge case handling. |
| Example Quality | Three excellent examples beat ten mediocre ones, with mislabeled examples degrading performance. |
What Is Few-Shot Prompting?
Few-shot prompting includes a small number of input-output examples in the prompt, showing the model exactly what kind of output you expect. This technique, popularized by the original GPT-3 paper, demonstrates that language models can learn new tasks from just a handful of examples provided in context, no gradient updates or retraining required.
The 'shot' in few-shot refers to examples: zero-shot has none, one-shot has one, few-shot typically has 3-10. The model reads the examples and infers the task format, output style, and any implicit constraints from the pattern. This in-context learning is one of the most remarkable capabilities of large language models.
When Few-Shot Prompting Helps
Few-shot examples are most valuable when you need a specific output format (JSON with exact field names, a particular template), are working on specialized domains the model might not default to correctly (medical coding, legal citation format, internal jargon), need consistent handling of edge cases (how to classify borderline examples), or want a particular writing style that's hard to describe in words.
Research consistently shows that the quality of examples matters more than quantity. Three excellent examples beat ten mediocre ones. Examples should be representative of the actual distribution of inputs you expect, cover diverse cases rather than repetitive easy ones, and always produce the correct output (mislabeled examples can degrade performance significantly).
Designing Good Examples
Format your examples consistently. If you're doing classification, always use the same label format ('Label: positive' rather than sometimes 'Positive', sometimes 'POSITIVE'). If generating structured data, show complete, valid examples rather than abbreviated ones. The model pattern-matches on every detail of your examples.
Order matters: place examples that are most similar to the test input at the end, just before the actual query. Recency bias means the model attends more to recent examples. For difficult or ambiguous examples, it helps to include a brief explanation alongside the answer, showing not just what the output should be but why, this teaches the model the underlying reasoning pattern.
Read next
Zero-Shot Prompting: Getting Results Without Examples
Zero-shot prompting asks an LLM to perform a task with no examples, relying entirely on the model's pretrained knowledge and instruction-following ability.
Prompt Engineering: The Complete Guide
Master the art and science of writing effective prompts, from basic techniques to advanced methods like chain-of-thought, few-shot learning, and structured output generation.
In-Context Learning: How LLMs Learn from Examples
How large language models adapt to new tasks from examples in the prompt, without gradient updates or fine-tuning, and what this capability means for AI flexibility.
