Few-Shot Prompting
Category: Foundational patterns
Few-shot prompting includes a handful of solved input–output examples in the prompt so the model infers the pattern and applies it to a new input. It steers format and behavior without any fine-tuning.
What it is
Few-Shot PromptingFew-shot prompting (also called in-context learning) demonstrates the task by embedding a small number of examples — typically one to a few — directly in the prompt. The model generalizes from the demonstrated mapping to the new input, learning "on the fly" from context rather than from updated weights.
This was a headline finding of the GPT-3 paper: sufficiently large models can perform many tasks from examples alone. Few-shot is especially effective for enforcing a specific output format, an unusual label set, or a house style that is hard to describe but easy to show.
When to use
- The output format is specific and easier to show than to describe.
- Zero-shot output is close but inconsistent in structure or style.
- The task uses a custom label set or domain conventions the model may not assume.
- You need behavior steering without the cost of fine-tuning.
How it works
- Choose a few representative, correct input–output pairs that cover the range of cases.
- Format every example identically so the pattern is unmistakable.
- Order and delimit examples consistently, then append the new input in the same shape.
- Let the model complete the pattern; add or swap examples if edge cases fail.
Illustrative structure
The structure is a repeated block: "Input: <example input> / Output: <example output>" two or three times, followed by "Input: <new input> / Output:" left for the model to complete. Every block uses identical formatting so the mapping is explicit.
Pitfalls
- Examples consume tokens and add latency; too many can crowd out the actual input.
- Biased or unrepresentative examples skew predictions (e.g. a majority-label bias).
- Inconsistent formatting across examples confuses the pattern the model should copy.
- Example order can affect results; test rather than assume.
Frequently asked questions
What is Few-Shot Prompting?
Few-shot prompting includes a handful of solved input–output examples in the prompt so the model infers the pattern and applies it to a new input. It steers format and behavior without any fine-tuning.
When should you use Few-Shot Prompting?
The output format is specific and easier to show than to describe. Zero-shot output is close but inconsistent in structure or style. The task uses a custom label set or domain conventions the model may not assume. You need behavior steering without the cost of fine-tuning.
What are common pitfalls of Few-Shot Prompting?
Examples consume tokens and add latency; too many can crowd out the actual input. Biased or unrepresentative examples skew predictions (e.g. a majority-label bias). Inconsistent formatting across examples confuses the pattern the model should copy. Example order can affect results; test rather than assume.
Sources
Related techniques
← All prompt engineering techniques
Apply Few-Shot Prompting with Prompeteer, the Agentic Contextual AI Platform →