Few-shot prompting gives a model a small set of input-and-output examples to show the pattern expected for a task. It can improve consistency for classification, extraction, rewriting and formatting. The quality of the examples matters more than simply adding more of them.
Choose examples that represent the task
Select examples that cover common inputs and meaningful variations. If a classifier has several categories, include examples from each category and cases that are easy to confuse. For extraction, include complete, partial and missing-field examples. Avoid choosing only the easiest cases.
Make the input-output relationship explicit
Keep examples in a consistent structure. Clearly label the input and the expected output, and use the same format that the live task will use. Do not mix instructions, commentary and examples in a way that makes it unclear which text is data and which text is the desired answer.
Include boundary cases and abstention
Show the model what to do when the input is incomplete, ambiguous or outside scope. If a safe answer is “unknown” or “needs review”, include such a case. This prevents the prompt from teaching the model that every input must receive a confident classification or invented field value.
Avoid accidental shortcuts and leakage
Examples should not reveal the answer through irrelevant cues such as record order, repeated names or a special token that only appears in one class. Keep evaluation examples separate from prompt examples so that test results measure generalisation rather than memorisation of the exact examples.
Change examples based on evidence
When results fail, classify the error first. The problem may be unclear task instructions, missing context, a confusing label definition or an edge case not represented. Revise the smallest relevant part and re-run a fixed test set. Keep a record of which prompt version and examples produced each result.
Further reading and resources
The article is original GrapeCrux editorial content. The following official documentation and technical resources provide deeper reading on the concepts discussed:
- OpenAI — Prompt engineering: few-shot learning
- Anthropic — Prompting best practices
- OpenAI — Evaluate agent workflows
Related GrapeCrux services and articles
Need help evaluating or implementing a similar solution? Start with the business requirement and discuss the appropriate scope with the GrapeCrux team.
Discuss a project ↗ Back to all blogs