LESSON 20 · PROMPT ENGINEERING

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.

25 min readBeginnerGenerative AI

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.
1

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.

ZERO-SHOT

Classify the message

Classify this support message as billing, technical, shipping, or account.
Task-specific examples: 0The model receives the instruction and the new input only.
FEW-SHOT

Classify using examples

“My card was charged twice” → billing
“Where is my package?” → shipping

Now classify: “I cannot reset my password.”
Task-specific examples: 2+The examples demonstrate the mapping before the new input.
Core idea:Zero-shot does not mean “give the model no instructions.” It means “give the model no task-specific demonstrations.”
2

Zero-shot vs. Few-shot

Both approaches can solve the same task. The main difference is whether examples are included in the prompt.

ZERO-SHOT

Instruction only

Extract the order ID from this message.
Return only the ID.
  • No demonstrations
  • Usually shorter prompt
  • Relies more on clear instructions
FEW-SHOT

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
Rule of thumb:Start with zero-shot when the task is straightforward. Add examples when the model needs help understanding your exact labels, format, or edge cases.
3

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.

TaskWhat should happen?
+
InputWhat should be processed?
+
ConstraintsWhat rules apply?
+
OutputWhat should be returned?

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.

TASKClassify
INPUTCustomer message
LABELS4 allowed values
CONSTRAINTExactly one
OUTPUTLabel only
4

Example 1: Zero-shot Classification

Classification is a common zero-shot use case because the labels can be stated directly in the instruction.

INPUT

Customer message

“The tracking page says delivered, but I never received the package.”

PROMPT

Zero-shot instruction

“Classify this message as billing, technical, shipping, or account. Return exactly one label.”

Expected taskThe model should select one label based on the instruction. No example mapping was supplied.

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.

5

Example 2: Zero-shot Extraction

You can ask a model to extract information without demonstrating the extraction on previous examples.

INPUTOrder #SAH-4821

Customer asks about delivery.

INSTRUCTIONExtract the order ID

Return only the ID.

OUTPUTSAH-4821

No example was provided.

Why it works:The requested field and output format are explicit, so the model has a clear operation to perform.
6

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.

</> Python
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.

7

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.

WEAK ZERO-SHOT
Classify this.

There is no label set, no output rule, and no definition of the task.

STRONGER ZERO-SHOT
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.

Define the taskUse an action such as classify, extract, rewrite, summarize, or translate.
Define the choicesList labels or allowed values when the output has a fixed set.
Define the formatSay whether you want text, bullets, JSON, a label, or another structure.
Define constraintsState important rules such as “do not invent facts.”
8

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.

Simple classificationSentiment, intent, or category labels with clear definitions.
Summarization“Summarize in 5 bullets for a beginner.”
TransformationTranslate, rewrite, shorten, or change tone.
ExtractionPull an email, date, ID, or named field from text.
Practical advantage:Zero-shot prompts are often shorter and easier to maintain because you do not have to store and update a demonstration set in every request.
9

When Zero-shot May Struggle

CHALLENGE

Unusual labels

Your internal categories have names whose meaning is not obvious.

Try: define the labels or add examples.
CHALLENGE

Strict formatting

The task has a subtle output pattern that is hard to describe with rules alone.

Try: add a demonstration.
BETTER FIT

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.

10

Zero-shot Is Not “No Context”

Zero-shot describes the absence of task-specific examples, not the absence of useful information.

A zero-shot request can still contain contextExamples are optional
Task instructionsCompany policyCurrent documentUser inputOutput rules

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.

11

Zero-shot + Context

This is where the previous lessons connect. You can provide relevant context and still use a zero-shot prompt.

Policy30-day returns with proof
+
InstructionDecide eligibility
+
Customer input“Can I return it?”
AnswerUse the policy
Key connection:RAG can retrieve relevant information, while zero-shot prompting can tell the model what operation to perform on that information. Retrieval and prompting solve different parts of the problem.
12

Mini-Project: Zero-shot Support Router

Build a small support-routing workflow that sends each incoming message to the right team.

1. Define teamsbilling, technical, shipping, account.
2. Write zero-shot promptState labels and definitions.
3. Add new messagesDo not provide demonstrations.
4. Validate outputReject labels outside the allowed set.
5. Build a test setInclude easy and ambiguous messages.
6. Measure resultsCompare accuracy and consistency.
Engineering challenge:After building the zero-shot version, create a few-shot version with 3–5 examples. Test both on the same unseen messages and decide which approach is better for your application.
PRACTICE

Zero-shot Challenge

Turn this vague request into a strong zero-shot prompt: “Classify this customer message.”

Define the taskDefine allowed labelsDefine output formatAdd an important constraint
QUICK QUIZ

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.