Zero-Shot vs Few-Shot Prompting

Gen AI · Prompt Engineering

Theory

Zero-shot prompting gives the model only an instruction and relies on what it learned in training to decide the format and behaviour. Few-shot prompting adds a handful of example input and output pairs before the real input, so the model copies the pattern. The examples are just extra context in the prompt: no training happens and the model itself does not change.

Few-shot helps most when the output format is unusual or strict, such as a company-specific label set, a fixed JSON shape or tricky edge cases like neutral reviews. A few diverse, correct examples usually beat many similar ones, and every example costs tokens on every call. Keep examples balanced, because the model tends to copy their patterns, including any bias towards one label.

Why we use it

It teaches the model your exact format and labelling rules in seconds, without collecting a training dataset or fine-tuning, which makes outputs more consistent and easier to parse.

When to use it

Start zero-shot for common tasks the model already handles well. Switch to few-shot when outputs drift in format or edge cases are handled wrongly. If you need hundreds of examples to get it right, fine-tuning may be the better tool.

How it works

  1. Write a clear zero-shot instruction
  2. Test it on real inputs
  3. Is the format and labelling consistent? Yes: Keep the zero-shot prompt. No: Add 2-5 diverse example pairs.
  4. Include at least one tricky edge case example
  5. Re-test and check that the labels are not skewed
  6. Use the prompt in production

Example

Few-shot prompt:
Classify sentiment as Positive/Negative/Neutral.

"Great service, fast delivery." -> Positive
"It broke after two days." -> Negative
"It arrived on Tuesday." -> Neutral
"Absolutely love this product!" -> ?

Model output: Positive

Key points

Gen AI topics

Foundations of Generative AI

Prompt Engineering

Retrieval & Embeddings

Customizing Model Behavior

AI Agents & Tool Use

Multimodal & Applied AI

Ethics, Cost & Careers

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Generative AI for the Data Stack

LLMs, prompt engineering, RAG, embeddings, agents and the tools shaping modern AI products — explained practically. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Section {{ sec.num }}

{{ sec.label }}

Gen AI  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

💡

{{ current.tldr }}

Explained

{{ para }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
See It In Action
{{ current.example }}
Key Takeaways — click to check off
{{ pt.mark }} {{ pt.text }}

Share this topic