Few-shot prompting improves consistency by showing a model what good inputs and outputs look like, but adding examples at random can make a prompt longer, less clear, and harder to maintain. This guide gives you a practical way to choose examples, decide how many to include, cover edge cases, and test whether each demonstration actually improves the response.
Overview
Few-shot prompting means including a small set of input-and-output demonstrations in a prompt before asking the model to handle a new input. The examples communicate more than the task description alone: they show the intended interpretation, tone, level of detail, output structure, and treatment of unusual cases.
There is no universal answer to “how many examples should I include in a prompt?” Start with the smallest set that represents the task clearly. In many workflows, a few carefully selected examples are more useful than a large collection of repetitive ones. The right number depends on the number of categories, the ambiguity of the inputs, the complexity of the format, the model’s available context, and the cost of processing a longer prompt.
For model-specific prompting, test the same example set with the model and settings you plan to use in production. A prompt that performs well in one model may need different demonstrations, ordering, or formatting in another. Treat the examples as part of the prompt’s behavior, not as decoration.
A simple selection rule
- Define the expected task and output before choosing examples.
- Include one clear example of the normal case.
- Add examples for the most important categories or decisions.
- Include an edge case only when it represents a real failure risk.
- Remove any example that is ambiguous, inconsistent, outdated, or redundant.
- Evaluate the prompt on inputs that were not included as demonstrations.
Few-shot examples should support the written instruction, not contradict it. If the task requires JSON, every demonstration should use valid JSON. If the task requires a short editorial summary, long explanatory examples may teach the wrong behavior.
Checklist by scenario
For classification prompts
Choose examples that make category boundaries easy to understand. Include at least one representative example for each high-value category when the category set is small. If there are many categories, prioritize categories that are commonly confused or have different downstream actions.
- Use labels exactly as they will appear in production.
- Include a straightforward example for each important label.
- Add a borderline example where two labels are easy to confuse.
- Show how to handle an input that belongs to no known category, if applicable.
- Avoid examples where the label depends on information that is not present in the input.
| Example type | Useful purpose | Risk if chosen poorly |
|---|---|---|
| Clear positive example | Establishes the basic pattern | Can be too easy to teach the real boundary |
| Boundary example | Clarifies a difficult distinction | May confuse the model if the label is debatable |
| Negative example | Shows what should not receive a label or format | Can introduce an unintended category |
| Rare edge case | Protects against a known production failure | Can overemphasize an unusual input |
For extraction and structured output
Match the target format precisely. If the application expects a JSON object, use the same keys, value types, null handling, and nesting in every example. Do not mix quoted numbers, numeric values, omitted fields, and empty strings unless those differences are intentional.
- Show one complete, ordinary record.
- Show how missing information is represented.
- Include a multi-value or nested case when that structure matters.
- Keep field names stable across all demonstrations.
- Pair examples with an explicit instruction to return only the requested structure.
For additional reliability, combine demonstrations with a schema or validation step where your implementation supports it. A few-shot example can illustrate the format, but it should not be the only control protecting downstream code.
For tone, style, and content transformations
Choose examples that reflect the actual editorial standard rather than merely sounding polished. Include a typical input, the desired level of detail, and a case requiring restraint. For example, a content workflow may need demonstrations showing how to preserve facts, remove unsupported claims, and keep a defined length.
- Match the intended audience and reading level.
- Keep the input length reasonably representative of production traffic.
- Show how the model should respond when information is incomplete.
- Avoid examples containing accidental phrases you do not want repeated.
- Use examples that demonstrate the format without turning into a full essay.
Reusable few-shot prompt template
Task:
[Describe the task, labels, constraints, and expected output.]
Rules:
- [Rule that applies to every input]
- [Rule for uncertainty or missing information]
- [Required output format]
Example 1
Input: [Clear, representative input]
Output: [Correct output]
Example 2
Input: [Commonly confused or important input]
Output: [Correct output]
Example 3
Input: [Relevant edge case, if needed]
Output: [Correct output]
Now process this input:
Input: [New input]
Output:
Keep the demonstrations in a consistent order: input first, output second, followed by a clear transition to the new task. If your application uses a system prompt, developer instruction, or separate message roles, place stable rules in the appropriate instruction layer and use demonstrations for task behavior and formatting.
What to double-check
Example coverage
Make a small inventory of the inputs your workflow receives. Compare that inventory with the examples in the prompt. Are common categories represented? Are the highest-risk mistakes covered? Are examples based on actual or realistic production inputs rather than convenient toy cases?
Coverage does not mean including every possible variation. It means representing the decisions the model must make. If two inputs look different but require the same reasoning and output, one strong example may be enough.
Consistency and ambiguity
Review each demonstration independently. Ask whether a human reviewer would agree with the output and whether the intended reason is clear from the input alone. Remove examples that depend on hidden context, unexplained preferences, or labels that could reasonably be interpreted another way.
Check for contradictions between the examples and the instructions. A single inconsistent demonstration can weaken confidence in the whole pattern, especially when the task is small or the examples are highly salient.
Ordering and context
Test whether example order changes the result. A practical starting point is to put the clearest example first, followed by examples that clarify boundaries, and end with a representative case close to the final input. This is a testing recommendation, not a universal rule; retain the order that performs best on your evaluation set.
Also check the full prompt length. Leave room for the user input and output, and verify the context limits and formatting behavior of the specific model or API you use. Provider limits and model behavior can change, so confirm them in the current documentation before deploying a larger demonstration set.
Evaluation beyond the examples
Never evaluate a few-shot prompt only on the demonstrations it contains. Create a separate test set with common cases, confusing cases, missing information, long inputs, and known edge cases. Compare zero-shot and few-shot versions when possible. The goal is not to make the prompt look consistent on its own examples; it is to improve performance on new inputs.
Record the model, prompt version, examples used, generation settings, expected output, and failure reason. This makes it easier to identify whether a problem comes from example selection, unclear instructions, model differences, or an input outside the workflow’s supported scope.
Common mistakes
- Adding examples until the prompt feels complete: More demonstrations increase length and may introduce noise. Add an example only to represent a category, clarify a boundary, or prevent a documented failure.
- Using only easy examples: Simple demonstrations establish the task but do not explain how to handle ambiguity. Include carefully chosen boundary cases.
- Mixing formats: Different punctuation, field names, headings, or label styles can make the target output unclear.
- Using contradictory labels: If similar inputs receive different outputs, explain the distinction or replace the examples.
- Teaching accidental content: The model may reproduce names, phrases, formatting, or disclaimers that appear repeatedly in demonstrations. Review examples for unwanted artifacts.
- Ignoring negative behavior: If the workflow must refuse, flag, or return an unknown result, demonstrate that behavior where it matters.
- Assuming one set works everywhere: Re-test examples when changing models, message structure, output constraints, or input distribution.
- Skipping version control: Store examples with the prompt version and evaluation results. A prompt library workflow makes later updates easier to review and roll back.
For safety-sensitive applications, examples should not be treated as a substitute for input validation, access controls, or prompt-injection defenses. Review the surrounding application as well as the prompt itself.
When to revisit
Revisit your few-shot examples whenever the underlying inputs, output requirements, or model setup changes. A useful review trigger is any measurable shift in production traffic or any new failure pattern that the current demonstrations do not explain.
- When you add, remove, or rename a classification category.
- When a new input type or customer workflow becomes common.
- When reviewers identify repeated errors or inconsistent formatting.
- When you change the model, API, message roles, output schema, or generation settings.
- Before seasonal planning cycles or other periods when input patterns may change.
- When examples contain outdated terminology, policies, product details, or editorial standards.
- When prompt monitoring shows rising failure rates, longer outputs, or more manual corrections.
Use this quick maintenance routine: collect recent failures, group them by cause, decide whether an example or instruction would address each cause, update the smallest necessary part of the prompt, and run the full evaluation set. Keep examples that improve unseen cases, not merely the examples that make the prompt look more explicit.
Finally, document why each demonstration exists. A short note such as “covers missing date,” “separates billing from technical support,” or “shows valid empty-array behavior” turns a prompt into an maintainable asset. When the workflow changes, you can review the purpose of each example instead of guessing which ones are safe to remove.