Back to blog
Prompting
Claude Code

Zero-Shot vs Few-Shot: Teaching AI with Examples

Thắng Đoàn
Thắng Đoàn

Model keeps picking the wrong format or style no matter how you phrase the instructions? That is zero-shot prompting hitting its limit. Examples teach the pattern faster than words do.

Zero-shot: instructions only

A zero-shot prompt gives the task and nothing else, like asking a stranger cold: "Which explanation of how snow forms is better, the detailed one or the brief one?" The model picks what it guesses you want, usually the more detailed one, even if you wanted the shorter answer.

Few-shot: show the pattern

A few-shot prompt includes examples of the behavior you want. Give two examples where the shorter explanation was chosen, and the model infers the preference. It is like handing a new employee three completed forms: they see the pattern and fill out the next one the same way. Google's prompting guide recommends always including examples, and if they are clear enough you can drop the written instructions entirely.

How many examples

Two to five is usually enough. More than that and the model can overfit: it copies the examples too closely instead of learning the general rule. Experiment to find the sweet spot for your task.

The trade-off

Examples cost tokens and attention, and inconsistent examples actively hurt: if example 1 uses bullets and example 2 uses numbers, the model gets confused, because it notices spacing, line breaks, and punctuation. Instructions are cheap and scale well, but they teach style and format far less precisely than three consistent examples.

The smallest test

Rerun your last zero-shot prompt with three consistent examples and compare the two outputs side by side.

Based on: Gemini API Prompting Strategies (ai.google.dev)

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

By subscribing you agree to receive the newsletter. No spam, and you can unsubscribe anytime.