Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 21 of 30
❮Prev Next❯

Zero-Shot and Few-Shot Prompting with GitHub Copilot

Module 4: Prompt Engineering ⏱ 9 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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 needed

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

    VS Code & GitHub: Zero-shot versus few-shot prompts Teach Copilot your log format with two examples.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading…

    <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
    1. Zero-shot: just the instruction. Copilot falls back to the most common pattern, not yours.
    2. Few-shot: give two or three examples of the exact format, then ask. Copilot follows the pattern.
    3. 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.

    😟 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
    🛠️ Solved with: Zero-shot vs few-shot

    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:

    DoWhy
    Use 2 or 3 short examplesEnough to show what varies and what stays fixed
    Make them agree with each otherMixed formats give a mixed answer
    Show the variation you needOne INFO and one WARN teaches that the level changes
    Use real-looking but fake dataNever 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:

    1. Be specific. Name the language, framework, inputs, outputs and rules. “Return 0 for unknown codes” beats “handle errors”.
    2. Give examples when the format matters (that’s few-shot).
    3. One task per prompt. Ask for the function, then the tests, then the docs. Big combined requests give shallow answers.
    4. Keep it short and relevant. Extra noise competes for space in a limited context window.
    5. Point at the right code. Select it, or add #file:src/discount.js, or @workspace for repo-wide questions.
    6. 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

    Online retail

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    A developer asks GitHub Copilot Chat to write a log statement for a failed payment. The prompt contains only the instruction. The response uses a generic console.error call instead of the team's custom log format. Which change to the prompt is most likely to produce output in the team's format?

    Question 2

    Question 2 of 5

    Which statement describes a zero-shot prompt?

    Question 3

    Question 3 of 5

    A developer is filling a JavaScript file with many similar test cases and wants GitHub Copilot inline suggestions to follow the same structure. The developer does not want to use Copilot Chat. What should the developer do?

    Question 4

    Question 4 of 5 · Select 2

    A team wants to improve the quality of GitHub Copilot Chat responses. Which TWO practices follow prompt crafting best practices?

    Question 5

    Question 5 of 5

    A development team found that few-shot prompts produce code in its standard error format. Developers often forget to paste the examples. The format must apply to every Copilot Chat request in the repository. What should the team do?

    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. 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. 2.When is zero-shot usually enough?Show

      For common, well-known tasks with a standard answer.

    3. 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. 4.What is a one-shot prompt?Show

      A few-shot prompt with exactly one example.

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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.