Guide4 min read

Zero-Shot vs Few-Shot Prompting

The terms "zero-shot" and "few-shot" refer to how many examples you include in your prompt before stating the actual task. This single variable has an outsized impact on the quality and consistency of AI output.

Zero-Shot: No Examples

In a zero-shot prompt, you describe the task and let the model figure out the format, conventions, and edge cases entirely from its training data.

💡 Note

Example: "Write a TypeScript function that validates an email address." — The model must decide the function name, parameter types, validation logic, and return type on its own.

When Zero-Shot Works Well

Zero-shot prompting is effective when:

  • The task is common and well-represented in training data (sorting, filtering, CRUD).
  • You don't need a specific output format.
  • Speed matters more than precision.
  • The task is simple enough that the model can't get it wrong.

Few-Shot: Leading by Example

In few-shot prompting, you provide 1–5 examples of input → output before the real task. The model treats these examples as a pattern to follow.

"Few-shot prompting is like showing someone what you want instead of explaining it. The model learns the format, style, and edge-case handling from your examples."

When to Use Few-Shot

Few-shot prompting shines when:

  • You need a specific output format (JSON schema, table, etc.).
  • The task involves domain-specific conventions the model may not know.
  • Consistency across multiple outputs is critical.
  • Zero-shot attempts produce inconsistent or incorrect results.

The Sweet Spot

In practice, 2–3 examples hit the sweet spot. One example can be ambiguous (the model doesn't know if a pattern is intentional or coincidental). Five or more examples waste context window tokens. Two to three examples clearly establish the pattern while being token-efficient.

  • Place the most representative example LAST (recency bias).
  • Keep examples consistent — don't mix styles or formats.
  • Include at least one edge case example if applicable.

Quick Reference

Use this decision guide:

  • Simple, common task → Zero-shot.
  • Specific format needed → One-shot (1 example).
  • Unusual or complex task → Few-shot (2–3 examples).
  • Highly structured or novel format → Many-shot (4–5 examples).
Back to Learning Hub