Zero-shot Prompting
Zero-shot prompting asks an LLM to perform a task without giving it task-specific examples in the prompt. You provide the task and requirements, and the model applies what it learned during training.
By the end of this lesson, you will be able to:
- Explain what zero-shot prompting means.
- Distinguish zero-shot from few-shot prompting.
- Write clear zero-shot prompts for classification, extraction, and generation.
- Use Python to run a real zero-shot LLM experiment.
- Recognize when zero-shot is a good fit and when examples are useful.
What Does “Zero-shot” Mean?
In a zero-shot prompt, you ask the model to complete a task without showing task-specific examples. “Zero-shot” refers to the number of examples supplied for that task: zero.
Classify the message
Classify this support message as billing, technical, shipping, or account.
Classify using examples
“My card was charged twice” → billing “Where is my package?” → shipping Now classify: “I cannot reset my password.”
Zero-shot vs. Few-shot
Both approaches can solve the same task. The main difference is whether examples are included in the prompt.
Instruction only
Extract the order ID from this message. Return only the ID.
- No demonstrations
- Usually shorter prompt
- Relies more on clear instructions
Instruction + demonstrations
“Order #A102” → A102 “Ref B908” → B908 Extract the ID from: “Order #C441”
- Examples show the desired behavior
- Useful for unusual formats
- Consumes additional context tokens
How a Zero-shot Prompt Works
The model already has broad capabilities from training. Your prompt specifies what you want it to do with the current input.
For example: Classify the message into exactly one of four labels. Return only the label. followed by the customer message is a zero-shot classification prompt.
Example 1: Zero-shot Classification
Classification is a common zero-shot use case because the labels can be stated directly in the instruction.
Customer message
“The tracking page says delivered, but I never received the package.”
Zero-shot instruction
“Classify this message as billing, technical, shipping, or account. Return exactly one label.”
Production tip: If the labels are similar, define each label in the prompt. Clear label definitions are still zero-shot as long as you do not provide task-specific input/output demonstrations.
Example 2: Zero-shot Extraction
You can ask a model to extract information without demonstrating the extraction on previous examples.
Customer asks about delivery.
Return only the ID.
No example was provided.
Run a Real Zero-shot Experiment in Python
Try the same customer messages with a clear zero-shot classification instruction. The code supplies no task-specific examples.
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
messages = [
"My card was charged twice for one order.",
"The tracking page says delivered, but my package is missing.",
]
instruction = """Classify each customer message as exactly one of:
billing, technical, shipping, account.
Return only the label. Do not add an explanation."""
for message in messages:
response = client.responses.create(
model="gpt-5-mini",
input=[
{"role": "system", "content": instruction},
{"role": "user", "content": message},
],
)
print(message, "->", response.output_text)Important: This is zero-shot because there are no examples such as “message → label” in the prompt. Keep the API key in an environment variable and validate the returned label in production code.
Clear Instructions Matter More in Zero-shot
When you remove examples, the instruction carries more of the burden. Compare a vague request with a precise one.
Classify this.
There is no label set, no output rule, and no definition of the task.
Classify the message as billing, technical, shipping, or account. Return exactly one label and nothing else.
The task, allowed labels, and output format are explicit.
When Zero-shot Works Well
Zero-shot is especially useful when the task is familiar, the instruction is unambiguous, and the desired output is easy to describe.
When Zero-shot May Struggle
Unusual labels
Your internal categories have names whose meaning is not obvious.
Try: define the labels or add examples.Strict formatting
The task has a subtle output pattern that is hard to describe with rules alone.
Try: add a demonstration.Few-shot
A small set of representative examples can show the exact mapping you want.
Try: compare zero-shot and few-shot on the same test set.Zero-shot is not automatically worse than few-shot. The right choice depends on task complexity, consistency requirements, prompt length, cost, and evaluation results.
Zero-shot Is Not “No Context”
Zero-shot describes the absence of task-specific examples, not the absence of useful information.
For example, “Using this return policy, decide whether this order is eligible. Return yes or no.” can be zero-shot even though the policy is included. There are still zero task-specific demonstrations.
Zero-shot + Context
This is where the previous lessons connect. You can provide relevant context and still use a zero-shot prompt.
Mini-Project: Zero-shot Support Router
Build a small support-routing workflow that sends each incoming message to the right team.
Zero-shot Challenge
Turn this vague request into a strong zero-shot prompt: “Classify this customer message.”
Classify the customer message as exactly one of:
billing, technical, shipping, account.
Return only the label.
Do not invent a category or add an explanation.
CUSTOMER MESSAGE:
{message}Test yourself
What makes a prompt zero-shot?
30-Second Recap
- Zero-shot means performing a task without task-specific demonstrations in the prompt.
- It can still use instructions, retrieved context, documents, policies, and output constraints.
- Clear task definitions, labels, formats, and constraints are especially important.
- Zero-shot is useful for many familiar tasks such as classification, extraction, summarization, and transformation.
- Few-shot prompting becomes useful when examples communicate a pattern that is difficult to describe.
- Evaluate zero-shot and few-shot approaches on representative inputs before choosing one for production.