Why few-shot still works
Modern models follow instructions well, so few-shot has lost ground. But it remains the most reliable way to anchor an exact output format — especially for unusual shapes (a specific JSON schema, a custom DSL, a multi-section response). Three concrete examples teach the model your format faster than three paragraphs of prose.
Pair few-shot with structured outputs (OpenAI strict mode, Anthropic tool calling) for the strongest guarantee: examples teach the model what each field means; the schema enforces what each field must look like.
FAQ
- Which style works best?
- XML for Claude (its training favours XML-tagged sections). Markdown for GPT and Gemini. JSON for tool-call style outputs. Q/A for the simplest cases. The formatter lets you switch and compare.
- How many examples?
- 3–5 is a sweet spot for most tasks. More than ~10 risks the model "averaging" instead of generalising. If you need many examples, consider fine-tuning instead.
- Should examples be hard or easy?
- Mix. Include 1–2 easy / canonical cases (anchor the format) plus 1–2 edge cases (anchor the policy). Avoid stacking only edge cases — the model overweights the unusual.
- Where in the prompt should examples go?
- After instructions, before the user query.
{role}{task}{examples}{user_input}. Recent models tolerate other orderings, but this layout is most reliable.