aiwithgrant
about me
LESSON 5 OF 127 min read

Few-Shot Prompting

Few-Shot Prompting

Few-shot prompting means giving the AI examples of what you want before asking it to do the task. It's the single most reliable technique for getting consistent, formatted outputs.

Zero-Shot vs Few-Shot

Zero-shot means you just describe what you want. Few-shot means you show examples first, then ask.

Here's a zero-shot prompt:

text
Classify the sentiment of this review as positive, negative, or neutral:
"The battery life is incredible but the camera is disappointing."

Here's the same task as a few-shot prompt:

text
Classify the sentiment of each review:

Review: "Absolutely love this product, best purchase ever!"
Sentiment: positive

Review: "Broke after two days. Complete waste of money."
Sentiment: negative

Review: "It works fine. Nothing special."
Sentiment: neutral

Review: "The battery life is incredible but the camera is disappointing."
Sentiment:

The few-shot version is more reliable because the model can see exactly what format and logic you expect.

Structuring Your Examples

The best few-shot prompts follow this pattern:

text
[Instruction describing the task]

[Example input 1]
[Example output 1]

[Example input 2]
[Example output 2]

[Actual input]
[Let the model complete]

How Many Examples?

1-2 examples work for simple formatting tasks
3-5 examples work for classification and extraction
5+ rarely needed — if you need more, the task might be too complex for few-shot alone

Pro Tip: Include Edge Cases

If your task has tricky edge cases, make one of your examples cover it. The model learns from the patterns you show it.