LESSON · 1 OF 4

Zero-shot vs few-shot

Zero-shot vs few-shot

A zero-shot prompt asks the model to do something with no examples. You just describe the task and hope your words are enough:

bash
claude -p "Classify this support message as billing, technical, or other: My card was charged twice this month"

That often works. But when the answer has a shape you care about (a label, a format, a particular style), plain words leave room to guess. The model might reply billing, or This looks like a billing issue., or a full paragraph. You asked for a category and got a conversation.

Few-shot: show, then ask

A few-shot prompt gives the model a few worked examples before the real question. Instead of only describing the task, you demonstrate it:

bash
claude -p "Classify each message as billing, technical, or other.

Message: My card was charged twice
Category: billing

Message: The app crashes when I upload a photo
Category: technical

Message: Do you have an office in Berlin?
Category:"

The model reads your two examples, picks up the pattern (one message in, one lowercase label out), and answers the last one the same way: other. You never explained the format in words. The examples did it.

Why examples steer the model

Recall from the first topic that an LLM predicts the most plausible continuation of the text it's given. When you show it two lines that both end in a single lowercase category, the most plausible next line is another single lowercase category. Examples don't teach the model new knowledge. They set the pattern it continues.

So the rule of thumb is: if a clear instruction gets you what you want, stay zero-shot - it's shorter and cheaper. Reach for few-shot when the output shape matters and words alone keep missing it.

Next: what separates examples that steer the model well from ones that confuse it.


Your lab setup

This VM comes preconfigured with your AI keys - just type claude to get started. Your key and URL are already set as $OPENAI_BASE_URL and $OPENAI_API_KEY.

Spin up a fresh environment and practice live.
linux-basic-ai · fresh machine · ready in under a minute