Developer Experience

Few-Shot Prompting

A prompting technique where you include a few examples of the desired input-output format in your prompt, helping the model understand exactly what you want without any fine-tuning.

Why it matters

Few-shot prompting is one of the most effective ways to get consistent, formatted output from a language model. Instead of describing what you want in words, you show it with examples.

How it works

Instead of telling the model what to do in abstract terms, you include 2-5 concrete examples of inputs and their expected outputs directly in the prompt. The model uses these examples to infer the pattern and apply it to new inputs.

The spectrum

  • Zero-shot — no examples, just an instruction. Works for simple tasks the model already understands well.
  • One-shot — a single example. Often enough if the pattern is clear.
  • Few-shot — 2-5 examples. More reliable for complex or ambiguous formats.

When to use it

  • Format control — when you need output in a specific structure (JSON, CSV, particular heading style).
  • Classification — when labeling items and the categories are not obvious from their names.
  • Style matching — when you want the model to write in a particular voice or tone.
  • Edge case handling — include an example that covers a tricky case to prevent the model from getting it wrong.

Tips

Choose diverse examples that cover the range of inputs the model will see. Put your most representative example first. If the model ignores your examples, try adding an explicit instruction like "Follow the exact format shown in the examples above."