learn·5 min read

Few-Shot Prompting: Teaching by Example

By Keimodel Team·

Few-shot prompting provides examples directly in the prompt, showing the model exactly what you want rather than just describing it.

Key Takeaways

TakeawayDetails
Example CountFew-shot typically uses 3-10 examples, with quality mattering more than quantity.
In-Context LearningModels learn new tasks from examples without gradient updates or retraining required.
Format ConsistencyExamples should use identical formatting and complete, valid structures for pattern matching.
Example OrderingPlace most similar examples at the end due to recency bias in model attention.
Use CasesMost valuable for specific output formats, specialized domains, and consistent edge case handling.
Example QualityThree 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.

few-shotpromptingin-context learningzero-shot