Few-shot Prompting
Few-shot prompting includes a small number of examples in the prompt to show the model the desired pattern.
Prerequisites
What Is Few-Shot Prompting?
Few-shot prompting adds a small number of worked examples to the prompt — showing an input and the desired output a couple of times — before asking the model to do the same thing for a new input. Instead of describing the task purely in words, you're demonstrating it.
Instruction
Task DescriptionWhat the model is being asked to do.
Example 1
Worked ExampleShows the desired input-output pattern.
Example 2
Reinforces PatternA second demonstration of the same pattern.
New Input
Unseen CaseThe actual input the model needs to handle.
Model Output
Follows the PatternGenerated by demonstration, not description.
Key Idea
Examples do work that instructions alone often can't — they show format, tone, and edge-case handling concretely instead of describing them abstractly.
Choosing Good Examples
- Representative — examples should reflect the range of inputs the model will actually see, including tricky edge cases if they matter.
- Consistent — every example should follow the exact format you want the model to produce, since the model will pattern-match the format as much as the content.
- Few, not many — two or three well-chosen examples are often enough; padding the prompt with many similar examples adds cost without adding much signal.
- Ordered thoughtfully — some tasks are sensitive to example order; if results seem inconsistent, try reordering or varying which examples are shown.
A Real-World Example
A team wants a model to rewrite messy customer messages into a clean, structured ticket summary with a fixed format. Zero-shot instructions alone often drift on formatting. Showing two or three examples of "messy message → clean ticket summary" pairs makes the desired format far more concrete, and the model's output becomes noticeably more consistent.
Common Mistakes
Using inconsistent formatting across examples
If your examples don't agree with each other on format, the model has no single consistent pattern to follow.
Including too many examples
Beyond a handful of well-chosen examples, additional ones usually add token cost without meaningfully improving results.
Using unrepresentative examples
Examples that don't reflect the real range of inputs can teach the model the wrong pattern for edge cases.
Reaching for few-shot when the task is already simple and well-defined
Adding examples has a cost — if zero-shot already works reliably, few-shot may be unnecessary overhead.
Interview Question
What is few-shot prompting, and how would you choose good examples for it?
Few-shot prompting includes a small number of worked input-output examples in the prompt before asking the model to handle a new input, showing the desired pattern instead of only describing it. Good examples are representative of the real range of inputs, consistent with each other in format, and few in number — two or three well-chosen examples usually beat many redundant ones. It's especially useful when a task has a specific format or edge-case handling that plain instructions alone struggle to convey reliably.
What an interviewer may ask next
- Why might inconsistent formatting across your examples hurt results?
- When would zero-shot prompting be preferable to few-shot?
- How many examples are usually enough, and why not just add more?
Explain It in 30 Seconds
Few-shot prompting shows a model a small number of example input-output pairs before asking it to handle a new input, demonstrating the desired pattern instead of only describing it in words. Good examples are representative, consistently formatted, and few in number — a couple of well-chosen examples usually work better than many redundant ones. It's most useful when a task has a specific format or edge cases that instructions alone don't reliably convey.