DEVSAIO

Few-shot prompting: teach a model with examples

Show the model 2–5 examples of input and output and it will follow the pattern. Here's how to choose good examples.

DEVSAIO team · 2 min read
Share on X

Few-shot prompting means including a few worked examples in your prompt. The model picks up the pattern (format, tone, level of detail) far better than from instructions alone.

Example: support ticket tagging

python
messages = [
    {"role": "system", "content": "Tag each support message with one category and a priority 1-3."},
    {"role": "user", "content": "I was charged twice this month!"},
    {"role": "assistant", "content": "billing | 1"},
    {"role": "user", "content": "How do I change my profile photo?"},
    {"role": "assistant", "content": "account | 3"},
    {"role": "user", "content": "The API returns 500 for every request since this morning."},
    {"role": "assistant", "content": "technical | 1"},
    {"role": "user", "content": new_message},
]
r = client.chat.completions.create(model="claude-haiku-5-5", temperature=0, messages=messages)

Writing examples as previous user/assistant turns is a clean way to do it.

Choosing good examples

  • Cover the variety you expect: different categories, lengths and tricky cases.
  • Include an edge case: an ambiguous input and how you want it handled.
  • Keep them correct. The model copies mistakes as faithfully as good answers.
  • Match the real format exactly, including punctuation and capitalisation.

How many?

Usually 2–5. More examples help with subtle tasks but add input tokens to every request, so stop when quality stops improving.

Why it's great for small models

Few-shot examples close much of the gap between small and large models on structured tasks, letting you use a much cheaper model (small vs large).

Try it with one API key

Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.

Keep reading