If you repeatedly ask AI to summarize, categorize, or transform data into a specific format, the issue may not be with the model. It could be that the instructions are too abstract. We say, "create a neat summary" or "categorize by type," but do not show what the correct output looks like.
This is where few-shot prompting comes in handy. This technique involves providing several input and output examples within the prompt, then asking AI to work on new data following the same pattern. Unlike regular prompts that only contain commands, this approach teaches patterns through examples.
Google explains that a single example is called one-shot prompting, while multiple examples are referred to as few-shot prompting. Anthropic's documentation also mentions relevant examples as an effective way to enhance consistency in format and style of output. However, examples must be chosen carefully because AI can mimic incorrect patterns if our examples are inconsistent.
When is this technique more useful than long instructions?
Few-shot prompting is suitable for tasks that have repetitive patterns, especially when rules are difficult to explain with words alone. For example:
- Transforming meeting notes into a task list.
- Categorizing customer inquiries based on the type of issue.
- Standardizing article titles into a uniform format.
- Labeling user comments.
- Converting product descriptions into promotional sentences with a specific style.
- Filtering important information from emails or documents.
Imagine asking a new employee to archive documents. The instruction "archive neatly" might lead to many interpretations. But if you show three documents along with their destination folders, that person has a clearer reference. Few-shot prompting works on the same principle.
Basic structure of a few-shot prompt
Such prompts typically have five parts: role or context, brief rules, examples, new data, and output format. You don't always have to use all of them, but this structure helps reduce ambiguity.
You are helping to categorize customer inquiries into the available categories.Categories: Shipping, Payment, Returns, OthersExample 1
Input: My package hasn't arrived even though the status says it has been shipped.
Output: ShippingExample 2
Input: I want to cancel my order and request a refund.
Output: ReturnsExample 3
Input: Why was my card declined when paying?
Output: PaymentTask
Input: My tracking number hasn't shown any changes for three days.
Output:The examples are brief but provide important information: what categories are available, how to interpret the cases, and the final answer should be a concise label.
How to choose the right examples
1. Choose examples that are truly similar to the task
Examples that are too far from real cases are not very helpful. If you want to categorize customer complaints, use examples that closely resemble customer language, including short sentences, light typos, or indirect questions.
Examples that are too clean, like "I am experiencing a shipping issue," may not represent real input such as "since yesterday the status is still in the warehouse, is this normal?".
2. Show variation, not overly narrow patterns
Do not make all examples have the same sentence structure. If all examples always start with "I want...", AI might become too fixated on that pattern. Provide variation in sentence length, terminology, and how people express their intentions.
3. Ensure labels and results are consistent
If two examples with similar meanings are labeled differently without explanation, AI will struggle to understand the actual rules. Double-check examples before including them in the prompt. One incorrect example can be more confusing than having no examples at all.
4. Include edge cases if they frequently occur
Edge cases are situations that could fit into two categories. For example, a customer complains about a late package while also requesting a refund. Add examples like this and explain their priority.
Combined case example
Input: The package is late and I want my money back.
Output: Returns
Note: If the customer explicitly requests a refund, choose Returns.Ready-to-use examples for everyday tasks
Here is a template that can be used to transform raw notes into an actionable task list. Replace the parts in square brackets with your needs.
You are transforming raw notes into a task list that can be acted upon immediately.Rules:
- Use the format: [Task] — [Responsible Person] — [Deadline]
- If the responsible person or deadline is not mentioned, write "Not determined".
- Do not add information that is not in the notes.
- Use short sentences starting with a verb.Example 1
Notes: Rina will send the design revisions by Friday.
Output: Send design revisions — Rina — FridayExample 2
Notes: The team needs to double-check the package prices, but no one has been assigned yet.
Output: Double-check package prices — Not determined — Not determinedNew notes:
[Paste your notes here]This template can be applied to meeting minutes, work WhatsApp messages, or personal notes. If the results are still too lengthy, add one more concise output example. AI usually finds it easier to follow length standards through concrete examples than through general requests like "don't be too verbose".
Do not include examples randomly
Few-shot prompting does not mean that more examples are always better. Lengthy examples will make the prompt harder to read and can consume context space. Start with a few of the most representative examples, then add new examples only when you encounter recurring failures.
Also, be aware of the risk of bias. If classification examples only use language from one user group, AI may more easily recognize that language style compared to others. For tasks involving important decisions, such as screening applications, health complaints, or risk assessments, examples should be tested with diverse data and still reviewed by humans.
Test with data that has not been used as examples
A common mistake is testing the prompt using examples that have already been provided. The results may look good because AI simply follows the existing patterns. Once the prompt is complete, prepare several new cases that are not included in the examples.
- Take five to ten real anonymized inputs.
- Run the prompt without changing the instructions each time.
- Note any incorrect, ambiguous, or overly lengthy results.
- Add corrective examples only for recurring issues.
- Repeat testing with another dataset.
In this way, the prompt evolves based on real problems, not on guesses. If the task is important, save the version of the prompt and the test results so that changes can be compared.
What does this mean for us?
When AI often provides answers with varying formats, do not immediately add long instructions. Try providing two or three examples of correct results, including one example that represents a difficult case. Show not only what needs to be done but also what the final result should look like.
Few-shot prompting is most effective for repetitive tasks with clear patterns. It is not a substitute for human oversight, especially when the results impact money, jobs, health, or personal data. However, for everyday tasks like tidying up notes, labeling, or standardizing formats, a few good examples are often more useful than a long paragraph of instructions.
Technical references: Google's prompt engineering guide and Anthropic's guide on using examples in prompts.
Sources & further reading
- Fine-tuning, distillation, and prompt engineering — Google for Developers
- Prompting best practices — Anthropic Documentation
– Rio Yotto @rioyotto
