Zero-Shot Prompting
By the Syncfusion DevTutorials team · Last updated
Get results with no examples: why zero-shot works, the task, choices and format recipe, cleaning replies in code, measuring on many inputs, defining labels, and its limits.
You ask a skilled colleague, "Is this customer email angry, happy, or neutral? Just give me one word." You don't show them any examples first. They just do it.
This is called zero-shot prompting. You give the model a task without any examples, and it uses what it has already learned to do the task. It is the simplest technique, and the one you will use most often.
The main idea: for common tasks, a clear instruction, a fixed set of answers, and an output format are often all you need.
A Real-World Example
Think about a new person starting at a help desk. On their first day, you say: "Sort these tickets into bug, question, or praise." You don't show them any sorted tickets first.
- They can do it, because they already know what a bug report and a thank-you note look like.
- They only do it well if the three labels are clear.
- If you had just said "Sort these tickets" with no labels, each person would make up their own groups.
A language model is like that new person. During training, it saw millions of examples of sorting, summarising, and translating. A zero-shot prompt only has to say which task to do, and how to answer.
What You Will Learn
In this lesson, you will learn:
- What zero-shot prompting is, and why it works.
- The tasks where zero-shot works well.
- A recipe with three parts for zero-shot prompts.
- How to clean up and check replies with code.
- How to measure a zero-shot prompt on many inputs.
- The signs that zero-shot is not enough.
The Prompt sandbox at the bottom of the page runs a real model in your browser. Use the Test tab to try a zero-shot prompt on many inputs at once. The code boxes run plain JavaScript without a model.
What Is Zero-Shot Prompting?
A shot is one worked example in a prompt. Zero-shot means zero examples. The prompt has only the instruction and the input.
A zero-shot prompt has no examples. The model uses what it learned in training, guided only by the instruction and the answer format.
It works because the model already learned many tasks from the text it was trained on:
- It has seen reviews next to star ratings, so it can tell whether a review is good or bad.
- It has seen articles next to summaries, so it can summarise.
- It has seen the same text in two languages, so it can translate.
The prompt doesn't teach the task. It chooses a task that the model already knows, and says how to answer.
Where Zero-Shot Works Well
| Task | Example of a zero-shot prompt |
|---|---|
| Classify (sort into labels) | Classify the review as positive, negative, or neutral. Reply with one word. |
| Summarise | Summarise the text in 2 sentences for a busy manager. |
| Translate | Translate the sentence into Spanish. Reply with the translation only. |
| Extract (pull out facts) | List every date in the email, one per line, as YYYY-MM-DD. |
| Rewrite | Rewrite the message in a polite, friendly tone. Keep it under 40 words. |
| Answer | Explain what an API is to a beginner in 3 sentences. |
All of these are common tasks, where it is clear what shape the answer should have.
The Zero-Shot Recipe
A good zero-shot prompt has three parts:
- The task, as an action word, like classify, summarise, or extract.
- The allowed answers, when there is a fixed set, like positive, negative, or neutral.
- The output format, like one word, one line, JSON, or under 50 words.
The next box builds zero-shot prompts from these three parts.
Build a zero-shot prompt from three parts
function zeroShot(task, labels, format, input) {
const choices = labels.length ? " as " + labels.slice(0, -1).join(", ") + ", or " + labels[labels.length - 1] : "";
return task + choices + ". " + format + "\n\nText: " + input;
}
console.log(zeroShot("Classify the review", ["positive", "negative", "neutral"], "Reply with one word.", "The grid is fast!"));
console.log("---");
console.log(zeroShot("Summarise the text in 2 sentences", [], "Write plain prose.", "(long text here)"));
Expected output:
Classify the review as positive, negative, or neutral. Reply with one word.
Text: The grid is fast!
---
Summarise the text in 2 sentences. Write plain prose.
Text: (long text here)
Try an unclear prompt and a prompt that follows the recipe, side by side:
Prompt A gets an opinion in a paragraph. Prompt B gets one label that code can use.
Easy Way to Remember: zero-shot means action word + choices + format. If the model has to make up the shape of the answer, the prompt is not finished.
Clean Up the Reply
Even when you say "Reply with one word", models add small extras, like a capital letter, a full stop at the end, or a word like "Sentiment:". Your code should clean up the reply before using it, and mark anything else as unknown.
Turn a raw reply into a label
const labels = ["positive", "negative", "neutral"];
function toLabel(reply) {
const words = reply.toLowerCase().match(/[a-z]+/g) || [];
const found = words.filter((w) => labels.includes(w));
return found.length === 1 ? found[0] : "unknown";
}
const replies = ["Positive", "Sentiment: negative.", "neutral", "It is positive, not negative.", "Great!"];
replies.forEach((r) => console.log(JSON.stringify(r), "->", toLabel(r)));
Expected output:
"Positive" -> positive
"Sentiment: negative." -> negative
"neutral" -> neutral
"It is positive, not negative." -> unknown
"Great!" -> unknown
- The first three are clean enough to use.
- The fourth names two labels, so the code can't trust it.
- The fifth names no labels at all.
When you count the "unknown" replies, you can see how well the model follows the format.
Measure on Many Inputs
One good reply proves very little. Run the prompt on a set of inputs where you already know the right answer, and count how many it gets right. This is the start of prompt evaluation, which you will learn about in full in Chapter 4.
Score a prompt on known answers
const results = [
{ review: "Fast and easy to use.", expected: "positive", got: "positive" },
{ review: "Export crashed twice.", expected: "negative", got: "negative" },
{ review: "It works.", expected: "neutral", got: "positive" },
{ review: "Support fixed it in an hour!", expected: "positive", got: "positive" },
{ review: "Docs are missing the API.", expected: "negative", got: "negative" },
];
const correct = results.filter((r) => r.got === r.expected).length;
console.log("Score:", correct + "/" + results.length);
results.filter((r) => r.got !== r.expected).forEach((r) => console.log("Wrong:", r.review, "->", r.got));
Expected output:
Score: 4/5
Wrong: It works. -> positive
The got values here are sample results written for this box. The mistake is a common one: a plain review with no feeling is called positive. This tells you that the word "neutral" needs a clearer meaning.
Now run a real test. The card checks each reply with one-of, so a reply must be exactly one of the allowed labels.
Define Your Labels
When a label is unclear, the model uses its own idea of what it means. You can fix this without examples: add a short meaning for each label.
Add a definition to each label
const labels = {
positive: "the writer is happy or would recommend it",
negative: "the writer reports a problem or is unhappy",
neutral: "a plain fact with no feeling either way",
};
const lines = Object.entries(labels).map(([name, meaning]) => "- " + name + ": " + meaning);
const instruction = "Classify the review using these labels:\n" + lines.join("\n") + "\nReply with one label only.";
console.log(instruction);
Expected output:
Classify the review using these labels:
- positive: the writer is happy or would recommend it
- negative: the writer reports a problem or is unhappy
- neutral: a plain fact with no feeling either way
Reply with one label only.
This is still zero-shot. There are no examples, only clearer rules. Run the test again with these meanings, and see if "It works. Nothing special." changes to neutral.
Zero-Shot Extraction
Zero-shot is not only for labels. It also works well for pulling facts out of text, if you name each field and its format. Ask for one field: value on each line, and then read the reply with a few lines of code.
Read fields from an extraction reply
// The prompt asked: "From the email, extract name, date (YYYY-MM-DD) and product.
// Reply with one field per line as field: value."
const reply = "name: Priya Shah\ndate: 2026-03-14\nproduct: Brightgrid Pro";
const fields = {};
for (const line of reply.split("\n")) {
const at = line.indexOf(":");
if (at > 0) fields[line.slice(0, at).trim()] = line.slice(at + 1).trim();
}
console.log(JSON.stringify(fields));
console.log("Date looks valid:", /^\d{4}-\d{2}-\d{2}$/.test(fields.date));
Expected output:
{"name":"Priya Shah","date":"2026-03-14","product":"Brightgrid Pro"}
Date looks valid: true
The reply here is a sample written for this box. With a real model, always check each field before you use it, like the date pattern above.
When Zero-Shot Is Not Enough
Zero-shot has trouble when the model can't guess what you want from words alone:
- Your own format. For example, product tags like
Grids > Export > Excel. - Your team's writing style. For example, the way your team writes release notes.
- Unusual labels. Labels that only make sense inside your company.
- Tricky cases. Sarcasm, reviews that are both good and bad, or very short inputs.
When your tests keep failing on cases like these, show the model a few examples. This is called few-shot prompting, and it is the next lesson.
Small models, like the one in your browser, follow zero-shot formats less reliably than big ones. Always clean up and check the reply with code. Never pass a raw reply straight into a database or another program.
Common mistakes
| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| No list of answers | "Classify the review" is enough. | List the labels: positive, negative, or neutral. | The model makes up labels like "mostly good". |
| No format | "It will reply with just the label." | Say "Reply with one word." | Code gets a paragraph, and can't read the label. |
| Using raw replies | "The model said positive, so I'll save it." | Clean up the reply, and check that it is an allowed label. | "Positive." and "Sentiment: positive" mess up your data. |
| Testing only one input | "It worked on my example." | Test on 5 to 10 inputs where you know the right answer. | The prompt fails on real data that you never tried. |
| Labels with no meaning | "Everyone knows what neutral means." | Add a one-line meaning for each label. | Plain reviews with no feeling are called positive or negative. |
| Forcing zero-shot | "I can fix it with better wording." | For your own formats or style, show examples. | You spend hours rewording, with no real improvement. |
Exercises
In each exercise, the last line should give back a value. Press Check to compare your value with the expected answer.
What to Remember
- Zero-shot prompts have no examples, only an instruction and an input.
- They work because the model has already learned many common tasks.
- The recipe is task + allowed answers + output format.
- Clean up replies with code, and count the unknown ones.
- Measure a prompt on many inputs where you know the right answer.
- Add a meaning for each label to fix unclear labels.
- For your own formats, your team's style, or tricky cases, use few-shot prompting.
Next: Few-Shot Prompting, where you teach the model a pattern with a few examples.