What few-shot prompting is
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 2–5 worked examples in the promptPromptThe input text sent to a language model — the question, instruction, or context that triggers a response.Learn more → before the actual question. The model learns the desired output format and style from the examples, then applies it to the new input. It is the fastest way to teach an LLMLLMLarge Language Model — a neural network trained on vast amounts of text data that can understand and generate human-quality language across a wide range of tasks.Learn more → a new task without fine-tuningFine-tuningThe process of further training a pre-trained model on a smaller, task-specific dataset to specialize its behavior for a particular use case.Learn more →.
LLMs are excellent at pattern matching from context. A few well-chosen examples can specify complex output structures, tone, reasoning style, or domain-specific formatting that would be difficult to describe verbally.
Structure of a few-shot prompt
Each example consists of an input followed by the desired output. Separate examples clearly — use consistent delimiters like 'Input:' and 'Output:', or XML tags like `<example>` / `</example>`. Consistency in formatting is more important than the specific delimiter choice.
After the examples, present the actual input with the same format but omit the output. The model will complete the pattern. End with 'Output:' (or your chosen label) to prime the generation.
How to choose good examples
Diversity matters more than quantity. Choose examples that cover different cases, different lengths, and different edge cases you expect in production. Two diverse examples usually outperform five similar ones.
Order the examples from simple to complex. The model applies the most recent examples most heavily, so put your most representative example last.
If your task involves specific formatting — tables, JSON, custom markup — show the exact format in the examples. The model will mirror it precisely.
Few-shot vs zero-shot vs fine-tuning
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 → (no examples) works for simple tasks with a large model. Few-shot is better when the output format is unusual, the domain is specialised, or zero-shot gives inconsistent results. Fine-tuning is only justified when you have 1000+ examples and need the lowest possible inferenceInferenceThe process of running a trained AI model to generate outputs — what happens when you send a prompt and receive a response.Learn more → cost for a specific task.
Start with zero-shot. If the output is inconsistent, add 2 examples. If still inconsistent, add 3 more. If you are writing more than 5 examples for every prompt, consider fine-tuning instead.