Techniques

Few-Shot Prompting

Including 1-5 worked examples of the desired input/output pattern in the prompt so the model can infer the task format and style.

First published April 14, 2026

Few-shot prompting "programs" the model by demonstration. Each example sets precedent: format, tone, depth, edge-case handling. The model generalizes from the examples to your real input.

The sweet spot is usually 2-4 examples. More than 5 adds cost without improving quality on modern models, and can actually hurt if the examples reinforce bias or contradict each other.

Example Prompt

Convert natural language to SQL.

Input: Show me customers who signed up last month.
Output: SELECT * FROM customers WHERE created_at >= date_trunc('month', now() - interval '1 month') AND created_at < date_trunc('month', now());

Input: Which products have more than 100 orders?
Output: SELECT product_id, COUNT(*) FROM orders GROUP BY product_id HAVING COUNT(*) > 100;

Input: How many users are in Texas?
Output:

When to use it

  • Output has a specific shape or style zero-shot doesn't capture
  • You have high-quality example pairs readily available
  • Task is narrow and consistent across inputs
  • Using a smaller model where zero-shot underperforms

When NOT to use it

  • Examples might bias the output away from the real input's context
  • The task is trivial for the model (wasted tokens)
  • Your examples contradict each other (worse than zero-shot)