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
  • Few-shot typically uses 3-10 examples, with quality mattering more than quantity.
  • Models learn new tasks from examples without gradient updates or retraining required.
  • Examples should use identical formatting and complete, valid structures for pattern matching.
  • Place most similar examples at the end due to recency bias in model attention.
  • Most valuable for specific output formats, specialized domains, and consistent edge case handling.
  • Three excellent examples beat ten mediocre ones, with mislabeled examples degrading performance.

What Is Few-Shot Prompting?

Few-shotFew-ShotA prompting technique where you include a small number of input-output examples in the prompt to demonstrate the desired task format and behavior to the model.Learn more → prompting includes a small number of input-output examples in the promptPromptThe input text sent to a language model — the question, instruction, or context that triggers a response.Learn more →, showing the model exactly what kind of output you expect. This technique, popularized by the original GPTGPTGenerative Pre-trained Transformer — the model architecture and family name behind OpenAI's most famous models, from GPT-2 to GPT-5.Learn more →-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-shotZero-ShotThe ability of a model to perform a task correctly from just a description, with no examples — demonstrating that it has generalized the concept from training.Learn more → has none, one-shotOne-ShotA prompting technique where exactly one example is provided to demonstrate the desired task format before presenting the actual query.Learn more → 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 learningIn-Context LearningThe ability of an LLM to learn from examples provided directly in the prompt, without any weight updates or training — just from seeing patterns in context.Learn more → 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