Few-Shot Prompting: Use Examples to Guide AI Output
Examples can be more precise than a long list of instructions. Few-shot prompting means showing an AI assistant a small number of input-and-output examples so it can infer the pattern you want. The technique is useful when the format, tone or decision rule is difficult to describe in words.
1. Define the target pattern
Write down what the assistant should do and what a successful result looks like. If you cannot describe the desired output, adding examples will not solve the underlying ambiguity.
2. Choose representative examples
Pick examples that cover the normal case and, when useful, one edge case. Prefer real examples that reflect the task rather than polished examples that hide important details.
3. Keep examples consistent
Use the same labels, field names and output structure in every example. Small inconsistencies can teach the wrong pattern.
4. Add the new input last
Separate the examples from the live task with clear labels. Tell the assistant to apply the demonstrated pattern to the new input rather than copying the examples.
5. Review for pattern drift
Check whether the output follows the demonstrated rule or simply imitates surface wording. If it drifts, simplify the examples or make the rule more explicit.
Example: classify support requests
Instead of saying “categorize these messages,” provide two or three labeled examples such as “I cannot reset my password” → Account access, then give the new message. Keep the labels fixed and ask for only the category plus a short reason.
Task: classify each customer message into one of these labels: Account access, Billing, Technical issue, or Other. Example 1: Message: “My password reset link has expired.” Label: Account access Example 2: Message: “I was charged twice for the same month.” Label: Billing Now classify the new message. Return only the label and one-sentence reason.
Common mistakes
- Using too many examples when two or three would establish the pattern.
- Choosing examples that contain different rules or inconsistent labels.
- Showing only easy examples and then expecting reliable behavior on edge cases.
- Letting examples become so long that the actual task is hard to find.
FAQ
Do I always need examples?
No. If the task is simple and the output format is obvious, a clear instruction may be enough.
How many examples should I use?
Start with a small set. Add another example only when it covers a meaningful case that the current prompt misses.
Worked scenario: Classifying customer feedback consistently
This is an illustrative example, not a report of a live product test. Replace the sample details with source material you can verify.
Feedback messages should be labeled Bug, Feature request or Billing question. Some messages may fit more than one label or be too vague.
Create a small set of representative examples, including one ambiguous message. Define the label rules and an “Unclear / needs review” fallback. Apply the same rules to each new message.
Test edge cases and inspect disagreements. Examples should represent the real message mix, avoid exposing personal data, and not force uncertain messages into a false category.
Classifying customer feedback consistently
Use this as a starting instruction with your preferred AI assistant. Replace bracketed placeholders with your own source material; this is an illustrative template, not a report of a real-world test.
Use representative, consistently labelled examples; test ambiguous cases and confirm the model has not inferred personal or sensitive details.