Zero-Shot and Few-Shot Prompting with GitHub Copilot
30-second answer
A zero-shot prompt gives Copilot only the instruction ("write a log line for a failed payment"), so it falls back to the most common pattern it knows. A few-shot prompt adds one or more examples of the input and output you want, then asks, so Copilot copies your format, naming and style. Use zero-shot for common, well-known tasks and few-shot when your format is unusual or house-specific. In the editor, a couple of example lines above the cursor work as few-shot for inline suggestions too. Best practice: be specific, give examples, keep each prompt to one task, and iterate on the answer.
Simulate it » No Azure account neededExam objective: 4.1.3 Use zero-shot and few-shot prompting. 4.1.4 Apply best practices for prompt crafting. (Skills measured as of August 7, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
<strong>Zero-shot</strong>: just the instruction. Copilot falls back to the most common pattern, not yours.
👆 Click the glowing item on screen to continue
Read the steps as text
- Zero-shot: just the instruction. Copilot falls back to the most common pattern, not yours.
- Few-shot: give two or three examples of the exact format, then ask. Copilot follows the pattern.
- It works in the editor too: write a couple of examples and Copilot’s inline suggestion continues the pattern. Best practice: be specific, give examples, keep it short, and iterate.
🧪 Simulation for learning. Screens are simplified versions of Visual Studio Code and github.com with GitHub Copilot; names, files and suggestions are examples. Not affiliated with GitHub or Microsoft, and nothing here touches your real account.
🖱️ Drag to rotate · scroll or pinch to zoom
Zero-shot and few-shot
Zero-shot: just the instruction. Few-shot: include one or more examples of the input and the output you want, then ask. Few-shot wins when your format is unusual.
🤔 What happens if…
Read this tour as text
- A vague prompt. Copilot only knows what is in the prompt. “Write a function” leaves it to guess the language, inputs, outputs and rules, so you get something generic.
- Structure: goal, context, constraints. A good prompt has a goal (what and why), context (which code, which framework) and constraints (style, edge cases, what not to do). Short is fine; vague is not.
- How context is chosen. In chat, Copilot uses the active file and any selection, plus what you add:
#file,#codebase(search your workspace),#terminalSelection, images, or a participant such as@workspace. Inline suggestions also use open tabs, so close unrelated ones. - Zero-shot and few-shot. Zero-shot: just the instruction. Few-shot: include one or more examples of the input and the output you want, then ask. Few-shot wins when your format is unusual.
- Break it down, then iterate. Split a big task into small steps and check each answer. Then iterate: keep what’s right and ask for the next change. Prompting is a conversation.
- Custom instructions. Repository instructions (
.github/copilot-instructions.md) and path-specific.instructions.mdfiles are added to requests automatically, so the house rules travel with every prompt. - Chat history is context too. Earlier messages in the same conversation go into the prompt. That helps follow-ups (“now add tests”) but old, unrelated turns can confuse the answer and fill the context window.
- The prompt process, end to end. Your words + selected context + instructions + history → the prompt. The model answers, you review, then refine. Better input, less clean-up.
A free terminal with GitHub Copilot CLI, git and gh. No tasks: install the CLI, start a session, try slash commands and tool permissions, or call the seats API.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Copilot ignores your unusual log format.
😊 THE SOLUTION
Show it two examples first: few-shot prompting.
- Instruction only✓ Fine for common tasks
- Unusual formats✓ Give examples first
- Inconsistent output✓ Same examples, same pattern
Start with a question
If you asked a new colleague to 'write a log line', would you get the format your team uses?
Probably not. They’d write what they wrote at their last job. Now imagine you show them two lines from your logs first: [INFO] 2026-11-19 10:02 | cart | Cart created. They’d get it right straight away.
Copilot works the same way. Asked with no examples (zero-shot), it writes console.error("Payment failed"), the most common answer on the internet. Shown two examples first (few-shot), it writes [ERROR] 2026-11-19 10:04 | payments | Payment failed for order 1004. Same model, same request. The examples did the work.
Explain it like I’m 10
The technical explanation
Zero-shot: the instruction alone
A zero-shot prompt is just the task: “Write a function that validates an Indian PIN code.” There are no examples of the answer. Copilot relies on patterns from its training data and the context it can see (your file, your selection, open tabs).
Zero-shot is fine, and fastest, when the task is common and has a standard answer:
- “Write a function that reverses a string.”
- “Explain what this regex does.” (with the regex selected)
- “/tests for applyDiscount” when your test style is already obvious from
tests/.
It goes wrong when the answer depends on your conventions: a log format, an error envelope, a naming scheme, a test layout nobody else uses. Copilot can’t guess those, so it picks the popular option.
Few-shot: show, then ask
A few-shot prompt puts one or more examples of the output (and often the input) before the real request. The model spots the pattern and continues it. With exactly one example it’s sometimes called one-shot.
Examples:
[INFO] 2026-11-19 10:02 | cart | Cart created
[WARN] 2026-11-19 10:03 | discount | Unknown code NOPE
Now: a failed payment for order 1004.
Copilot answers [ERROR] 2026-11-19 10:04 | payments | Payment failed for order 1004. It inferred the level, the date layout, the pipe separators and the module name from just two lines.
Tips for good examples:
| Do | Why |
|---|---|
| Use 2 or 3 short examples | Enough to show what varies and what stays fixed |
| Make them agree with each other | Mixed formats give a mixed answer |
| Show the variation you need | One INFO and one WARN teaches that the level changes |
| Use real-looking but fake data | Never paste real customer data into a prompt |
Few-shot in the editor
You don’t need chat for this. Inline suggestions read the code above and below the cursor, so examples in the file act as few-shot context:
// Format: [LEVEL] yyyy-mm-dd hh:mm | module | message
logLine('INFO', 'cart', 'Cart created');
logLine('WARN', 'discount', 'Unknown code NOPE');
// cursor here: Copilot suggests the next logLine(...) in the same shape
The same trick works for test cases, enum maps, SQL inserts and translation files. Write two by hand, then let Tab do the rest, and still read every line you accept.
Best practices for crafting prompts
The exam lists “apply best practices for prompt crafting” next to few-shot. These are the ones that matter most with Copilot:
- Be specific. Name the language, framework, inputs, outputs and rules. “Return 0 for unknown codes” beats “handle errors”.
- Give examples when the format matters (that’s few-shot).
- One task per prompt. Ask for the function, then the tests, then the docs. Big combined requests give shallow answers.
- Keep it short and relevant. Extra noise competes for space in a limited context window.
- Point at the right code. Select it, or add
#file:src/discount.js, or@workspacefor repo-wide questions. - Iterate. Treat the first answer as a draft. Say what to keep and what to change.
Architect level Why examples work so well on a language model
A large language model predicts the most likely next tokens given everything in the prompt. With no examples, “most likely” means most common across its training data. Examples change the odds: once two lines in the prompt share a pattern, the most likely continuation is a third line in that pattern. That’s also why conflicting examples hurt, and why output can still vary between runs. The model isn’t learning permanently; the examples only affect this request.
Real-world business scenario
Contoso (fictional)
- The problem
- The contoso-shop team asked Copilot Chat to add logging to new payment code. Every answer used console.log with free text, so their log search and alerts couldn't parse the lines, and reviewers rewrote them by hand.
- What they used
- Few-shot prompts with two real-format log lines for one-off work, then the format and one example moved into .github/copilot-instructions.md, plus a prompt file /add-logging for the repeated task.
- Why that choice
- Examples showed Copilot the exact layout. Putting them in repository instructions meant nobody had to remember to paste them.
- The result
- Generated log lines matched the house format on the first try in review, and the payment alerts started firing on the new code paths.
When to use it and when not to
✓ Use it when…
- Few-shot when your output must match a house format, naming scheme or style Copilot can't know.
- Few-shot in the editor for repetitive structures such as test cases, mappings or data rows.
- Zero-shot for common tasks with a standard answer, where examples would only add length.
✕ Think twice when…
- Pasting the same examples into every chat. Put standing rules in custom instructions instead.
- Using real customer records as examples. Make up clearly fake ones.
↔ Alternatives to consider
- Custom instructions (.github/copilot-instructions.md) for rules that apply to every request in the repo.
- Prompt files (.github/prompts/*.prompt.md) to save a good few-shot prompt and run it with /name.
Test yourself with exercises
5 original practice questions in the GH-300 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What's the difference between zero-shot and few-shot prompting?
Model answer
Zero-shot means I only give the instruction. Few-shot means I show a couple of examples of what I want first, then ask. With examples, Copilot matches my format instead of guessing the most common one.
Interviewer follows up
Is one example enough?
You
Often, yes. That's called one-shot. I add a second or third example when the pattern has variations, like different log levels, so Copilot sees what changes and what stays the same.
Intermediate How do you do few-shot prompting with inline suggestions, where there's no chat box?
Model answer
I write the first one or two items myself in the file, for example two test cases or two log calls, and put the cursor on the next line. Copilot reads the code above the cursor as context and continues the pattern as ghost text.
Experienced developer Your team's generated code keeps using a different error format from the house standard. Few-shot fixed it in one chat, but people forget. What do you do?
Model answer
I'd put the standard and one short example in .github/copilot-instructions.md so it's added to every chat request in the repo automatically. For a repeated task, I'd also save the few-shot prompt as a prompt file in .github/prompts so anyone can run it with a slash command.
Scenario A zero-shot prompt for a SQL migration gave you generic syntax for the wrong database. What would you change?
Model answer
I'd make it specific: name the database and version, paste or reference one existing migration from the repo as an example, and say what the new one must do. That's a few-shot prompt with the right context, and it nearly always lands closer.
Quick revision
Key points
- Zero-shot is the instruction only; Copilot uses the most common pattern it has seen.
- Few-shot adds examples of the output you want before the request; Copilot follows them.
- Few-shot wins for unusual or house-specific formats, naming and styles.
- Example lines above the cursor act as few-shot context for inline suggestions.
- Best practices: be specific, give examples, one task per prompt, keep it short, iterate.
Important terminology
- Zero-shot prompt
- A prompt that contains only the instruction and no examples of the output you want.
- Few-shot prompt
- A prompt that includes one or more worked examples of input and output before the actual request, so the model follows the pattern.
- One-shot prompt
- A few-shot prompt with exactly one example.
- Ghost text
- The grey inline suggestion Copilot shows in the editor, which you accept with Tab or dismiss with Esc.
- Iteration
- Refining a prompt or asking follow-up questions until the answer is right, instead of expecting a perfect result first time.
Common mistakes
- Expecting Copilot to guess a house format from a zero-shot prompt.
- Giving examples that disagree with each other, so the pattern is unclear.
- Packing several unrelated tasks into one long prompt.
Exam tips
- "Copilot ignores our custom format" = add examples (few-shot).
- "A prompt with no examples" = zero-shot. "With one example" = one-shot, a kind of few-shot.
- "Make the format apply to every chat in the repo" = custom instructions, not repeating examples each time.
Five quick revision questions
-
1.What do you add to turn a zero-shot prompt into a few-shot prompt?Show
Examples of the input and output you want.
-
2.When is zero-shot usually enough?Show
For common, well-known tasks with a standard answer.
-
3.How do you few-shot an inline suggestion?Show
Write one or two example lines above the cursor and let Copilot continue the pattern.
-
4.What is a one-shot prompt?Show
A few-shot prompt with exactly one example.
-
5.Name two prompt best practices.Show
Be specific and iterate (also give examples, one task per prompt, keep it short).
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Prompt Engineering Principles and Chat History
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.