Few-shot prompting
Teach the model a pattern by showing it a handful of examples before asking for the real output. Few-shot prompting is the simplest way to steer tone, format, and reasoning style without fine-tuning.
Why it works
Large language models are pattern matchers. When you prepend two or three input-output pairs, the model infers the hidden rule and applies it to the final query. This is especially effective for classification, structured extraction, and style transfer tasks.
The template
Example 1:
Input: "The app crashed when I clicked save."
Label: bug
Example 2:
Input: "Can you add dark mode?"
Label: feature_request
Example 3:
Input: "How do I export my data?"
Label: question
Now classify:
Input: "The login button does nothing on mobile."
Label: ▌
Rules of thumb
- •Three to five examples is the sweet spot. Fewer and the pattern is ambiguous; more and you waste context window.
- •Keep examples diverse. Cover edge cases so the model doesn't overfit to one surface-level pattern.
- •Delimit clearly. Use separators like
###or XML-style tags so the model can parse example boundaries reliably. - •Match your target format. If you want JSON output, show JSON examples. The model copies structure, not just content.
When to upgrade
If you find yourself writing more than eight examples or the pattern keeps breaking on novel inputs, it's time to move to a system prompt with explicit rules, or consider fine-tuning. Few-shot prompting shines for quick prototyping and low-volume classification pipelines.