Few-shot prompting gives an LLM a small set of input-output examples so it can infer the task, format, and decision boundaries you want. This guide explains how many examples to start with, how to choose representative pairs, and how to test whether they actually improve results. It also includes reusable prompt templates for classification, extraction, rewriting, and routing.
Overview
Few-shot prompting sits between zero-shot and one-shot prompting. A zero-shot prompt describes a task without examples. A one-shot prompt provides one worked example. A few-shot prompt provides several examples before asking the model to process a new input.
Examples can clarify requirements that are difficult to express in instructions alone: the preferred tone, the exact JSON shape, the boundary between labels, or how to handle missing information. They are especially useful when the task has a house style, several similar categories, or an output format that must be consistent.
There is no universal answer to “How many examples should I include?” Start with three to five carefully selected examples, then measure the result. Add examples only when they resolve a demonstrated ambiguity, cover an important class, or represent an edge case that causes errors. More examples are not automatically better. They consume context, increase maintenance work, and can introduce conflicting patterns.
A useful few-shot prompt separates the task instructions from the demonstrations and the live input. Clear delimiters make that separation visible:
Task instructions:
Classify each support message as billing, technical, account, or other.
Return JSON with the keys "label" and "reason". Use only the allowed labels.
Examples:
<example>
Input: I was charged twice for the same order.
Output: {"label":"billing","reason":"Duplicate charge"}
</example>
<example>
Input: My password reset link has expired.
Output: {"label":"account","reason":"Password recovery issue"}
</example>
New input:
<input>
{{customer_message}}
</input>
Keep the examples internally consistent. If one example returns a short reason and another returns a paragraph, the model has to infer which behavior is intended. For production use, test the prompt against a fixed evaluation set rather than judging it from one successful response. The LLM evaluation checklist can help organize checks for accuracy, format, safety, and cost.
Checklist by scenario
Classification
- List every allowed label in the instruction, even if some labels do not appear in the first examples.
- Choose examples that distinguish similar labels, not only obvious cases.
- Include at least one example for each high-impact or frequently confused category when practical.
- Show the required fallback behavior for ambiguous, empty, or out-of-scope input.
Classify the message using exactly one label: urgent, routine, or unclear.
Return only JSON: {"label":"..."}.
Examples:
Input: The production database is unavailable for all users.
Output: {"label":"urgent"}
Input: Please add a new team member next week.
Output: {"label":"routine"}
Input: Can someone look into this?
Output: {"label":"unclear"}
Message: {{message}}
Information extraction
- Show the complete output schema, including null behavior for missing fields.
- Use examples with different field combinations: all fields present, one field missing, and noisy wording.
- State whether values should be copied, normalized, or inferred.
- Demonstrate how to handle multiple entities or repeated values.
Extract the order number, customer email, and issue type.
Do not guess missing values. Use null when a field is absent.
Return valid JSON only.
Example:
Input: Order A-1042 arrived damaged. Contact me at sam@example.com.
Output: {"order_number":"A-1042","customer_email":"sam@example.com","issue_type":"damaged"}
Input: {{support_message}}
Output:
Rewriting and style transfer
- Choose examples that show the intended length, reading level, and voice.
- Preserve facts, names, numbers, and commitments unless the instruction says otherwise.
- Include one example with awkward or overly long source text to show the desired degree of editing.
- Say what must not change, such as technical terms or code.
Rewrite the text for a concise internal status update.
Preserve all dates, numbers, and technical terms. Use two sentences maximum.
Example:
Input: We are still investigating the issue and have not yet identified the root cause.
Output: We are investigating the issue. The root cause has not been identified.
Text:
{{text}}
Routing and tool selection
- Show the available routes and the conditions that distinguish them.
- Include a route for insufficient information rather than forcing a confident choice.
- Use examples where several tools appear relevant but only one is appropriate.
- Define the exact arguments or schema expected after routing.
For agent workflows, few-shot examples should clarify tool choice without replacing tool permissions, validation, or observability. Related guidance on tool descriptions and prompts and agent observability is useful when a prompt controls actions rather than producing text alone.
What to double-check
Example selection
Use examples that resemble real inputs in length, vocabulary, formatting, and difficulty. A set of perfectly clean examples may not prepare the model for spelling mistakes, partial records, mixed languages, or contradictory wording. Select examples deliberately from the cases your workflow actually receives. If the task has labels, balance the set enough to show each important distinction; do not let a common label hide a rare but consequential one.
Input-output alignment
Each output must answer its corresponding input. Keep pairs visually grouped and label them consistently. Do not place commentary between an example input and its output unless that commentary is part of the intended pattern. If the final response must be JSON, every demonstration should use valid JSON with the same field names and types.
Instructions versus demonstrations
Examples illustrate behavior; they should not be the only place where a critical rule appears. State constraints directly, including allowed labels, required fields, refusal or fallback behavior, and whether the model may infer information. Use delimiters such as XML-like tags, headings, or clearly marked blocks. For broader system-instruction design, see System Prompts Explained.
Context and message format
Check the target model’s current context limits and the message format supported by the API or application you use. A prompt that works in an interactive interface may need different role separation or escaping when sent through an API. Keep the examples short enough to leave room for the live input and the expected output. Recheck this whenever you change models, add retrieved documents, or introduce conversation history.
Evaluation
Compare zero-shot, one-shot, and few-shot versions on the same test cases. Track task accuracy, schema validity, consistency, latency, and token usage as relevant to the workflow. Review failures by category: unclear instructions, missing coverage, misleading examples, or model limitations. A few-shot prompt is an optimization, not a substitute for validation in a high-impact workflow.
Common mistakes
- Adding examples without a reason. More demonstrations can increase prompt length while leaving the actual failure unchanged. Add one when it addresses a known error.
- Using contradictory outputs. If similar inputs receive different labels or formats, explain the distinction or replace the examples.
- Showing only easy cases. Include boundary cases, missing values, unusual wording, and realistic noise.
- Overfitting to example wording. Vary phrasing so the model learns the rule rather than copying a keyword.
- Mixing instructions into data. Clearly mark untrusted user input and demonstration content, particularly when prompts process documents or messages.
- Expecting examples to enforce a schema. Pair examples with explicit output requirements and validate the returned data in application code.
- Changing several variables at once. When testing prompt optimization, change the examples, instructions, or model separately where possible so you can identify what helped.
When to revisit
Review a few-shot prompt before seasonal planning cycles, after a workflow or model change, and whenever the input distribution changes. Revisit it when you add a new label, language, product line, document type, or tool route. A prompt that performed well on last quarter’s cases may no longer represent current terminology or edge cases.
Use this maintenance checklist:
- Sample recent failures and identify which ones the current examples do not cover.
- Remove examples that are obsolete, redundant, or tied to a temporary process.
- Add the smallest number of examples needed to clarify new distinctions.
- Retest against a stable regression set before deploying the revision.
- Check output parsing, permissions, and downstream validation after changing formats.
- Record the prompt version and the reason for each example change.
The practical starting point is simple: write a clear zero-shot instruction, add three representative examples, test against real-looking cases, and expand only in response to measured failures. That workflow keeps few-shot prompting useful, reviewable, and adaptable as your LLM application evolves.