Your profile

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

Lesson 3 of 30
❮Prev Next❯

Validate Copilot Output and Use It Responsibly

Module 1: Responsible AI ⏱ 10 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

    You validate Copilot output because it predicts code and can't check it, so a suggestion can look right and still be wrong, insecure or outdated. Read it until you understand it, run tests with edge cases, lint it, let code scanning and dependency review check it, and keep human pull request review before merge. Operating Copilot responsibly also means giving it good context, keeping secrets and personal data out of prompts, and owning what you accept.

    Simulate it » No Azure account needed

    Exam objective: 1.2.1 Explain the need to validate AI output. 1.2.2 Identify how to operate GitHub Copilot responsibly. (Skills measured as of August 7, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    VS Code & GitHub: Validate what Copilot suggests Test a suggestion, find the bug, fix it before you merge.
    </> Embed

    Embed this simulation

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

    Loading…

    Copilot suggests a function that <strong>looks</strong> right. Before you press Tab, ask: what happens with an unknown code?

    👆 Click the glowing item on screen to continue

    Read the steps as text
    1. Copilot suggests a function that looks right. Before you press Tab, ask: what happens with an unknown code?
    2. Test it. A quick test with an edge case shows the suggestion returns NaN. Running code beats reading it.
    3. Fix, rerun, and only then commit. Review, test, lint and scan Copilot’s code exactly as you would a colleague’s, and never accept code you don’t understand.
    4. Keep the normal safeguards: pull request review by a person, CI tests and code scanning. Copilot speeds you up; it doesn’t replace the checks.

    🧪 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

    A suggestion passed a quick look and broke checkout in production.

    😊 THE SOLUTION

    Treat every suggestion as a draft: read, test, scan, review.

    • Pressing Tab without reading✓ Understand before you accept
    • No tests for edge cases✓ Generate and run tests
    • Insecure code slips in✓ Code scanning in CI
    🛠️ Solved with: Validation habits

    Start with a question

    Copilot wrote applyDiscount() in two seconds. It looks perfect. Do you press Tab and move on?

    Press Tab if you like, but don’t move on yet.

    Here’s what happened in contoso-shop. The suggestion handled SAVE10 and HALF nicely. Then a customer typed a code that didn’t exist, and the cart total became NaN. Nobody had asked “what about an unknown code?”

    Validating AI output means asking those questions before your users do. Read it, run it, test the odd cases, and let the usual checks look at it. Two seconds to write, two minutes to check. It’s still a great deal.

    Explain it like I’m 10

    Visual: validating a suggestion in motion

    Watch a suggestion that looks right fail a test, get fixed, and pass the checks before anyone merges it.

    ▶ Explainer video See it in motion 7 steps · 1 min 20 sec

    An animation of validating a GitHub Copilot suggestion in a sample shop app. Copilot suggests an applyDiscount function as ghost text and the developer accepts it. It works for a valid code, but a test with an unknown code fails because the result is NaN. The developer adds a default of zero, the tests pass, lint, code scanning and dependency review go green, and a person approves the pull request. Copilot code review only comments and does not count as the approval.
    Read the video script
    1. A suggestion appearsYou type the start of applyDiscount and pause. Copilot fills in the rest as grey ghost text. It reads cleanly, and it took two seconds.
    2. Accepted, and it worksYou press Tab. You try it with SAVE10 and a hundred, and you get ninety. It's tempting to stop right here.
    3. Test the odd caseNow the question Copilot never asked: what if the code doesn't exist? One small test, and it fails. The total comes back as not a number.
    4. It predicted, it didn’t checkHere's why. An unknown code makes pct undefined, and maths with undefined gives not a number. Copilot predicts what code usually looks like. It never ran this.
    5. Fix it, run it againThe fix is one line: default the percentage to zero. You run the tests again, and all five pass. Now you know it works, instead of hoping.
    6. The pipeline checks tooYou open a pull request. The linter, code scanning and dependency review run on it, because tests only catch what you thought to test.
    7. A person signs offCopilot code review leaves a comment, but it can't approve. Your teammate reads it, approves, and a person merges. Copilot sped you up. The checks made it right.

    The technical explanation

    Copilot predicts code. It doesn’t run it, test it or know your business rules. So the output needs the same checks as code from a new colleague, plus a bit more care because it sounds so sure of itself.

    Why validation isn’t optional

    • It can be wrong and look right. No warning appears on a bad suggestion.
    • It can be insecure. Insecure patterns exist in the code models learned from.
    • It can be outdated. The knowledge cut-off means old APIs and versions.
    • It can miss your rules. If a rule wasn’t in the context, Copilot didn’t see it.
    • You own it. Once you accept it, it’s your code.

    A validation routine that works

    1. 1 Read

      Understand every line. If you cannot explain it, ask Copilot to explain it, then check that against the code.

    2. 2 Test

      Run existing tests and add edge cases: empty input, zero, unknown values, very large numbers.

    3. 3 Lint and type check

      Let the linter and type checker flag likely bugs and unknown symbols.

    4. 4 Scan

      Code scanning finds vulnerabilities; dependency review checks any new packages.

    5. 5 Human review

      A teammate reviews the pull request. Required checks must pass before merge.

    From suggestion to merge

    In contoso-shop, the test that catches the bug is short:

    // tests/discount.test.js
    test('unknown code leaves the total unchanged', () => {
      expect(applyDiscount(100, 'NOPE')).toBe(100);   // fails: NaN
    });

    The fix is one line, const pct = CODES[code] ?? 0;, and then npm test passes. Ask Copilot for tests with /tests, but add the edge cases you care about yourself. If the same model wrote the code and the tests, both can share one wrong assumption.

    Operating Copilot responsibly every day

    HabitWhy
    Give clear context (open the right files, use #file, write a specific prompt)Better input means fewer wrong guesses
    Keep secrets and real personal data out of promptsPrompts leave your machine; use fake sample data
    Never accept code you don’t understandYou can’t review or maintain what you can’t explain
    Keep pull request review, CI and branch protectionCopilot speeds up writing, it doesn’t replace the gates
    Give feedback with thumbs up or downIt helps GitHub improve responses
    Say when Copilot helpedReviewers know where to look harder

    Copilot code review is useful here, but know its limits: it leaves comments and suggested changes, it never approves, and it doesn’t count toward required approvals. A person still signs off.

    Architect level Why tests written by the same model aren't enough

    If you ask Copilot to write applyDiscount and then its tests, both come from the same prompt and the same patterns. If the model assumed every code is valid, the tests may only use valid codes and pass happily. Write at least the edge-case tests yourself, or ask for them explicitly (“include an unknown code, a zero total and a negative total”), and review the expected values with the business rule in hand.

    Real-world business scenario

    Online retail

    Contoso Shop (fictional)

    The problem
    After adopting Copilot, the team shipped faster, but two production bugs in a month came from suggestions accepted without tests: a NaN total and a date bug at month end.
    What they used
    A validation routine in the team guide (read, test edge cases, lint, scan, review), a ruleset on main requiring one human approval plus passing tests, lint and CodeQL checks, and Copilot code review added as an extra reviewer.
    Why that choice
    Tests catch logic errors, scanning catches insecure patterns, and human review catches what neither thought of. Copilot code review adds comments without replacing the human approval.
    The result
    Bugs from AI-written code dropped back to the team's normal rate, and developers kept using Copilot for first drafts and test ideas.

    When to use it and when not to

    ✓ Use it when…

    • Every Copilot suggestion that goes into code you will commit, however small.
    • Suggestions that touch money, security, personal data or dates, where edge cases bite.
    • Copilot-written tests, which need review too.

    ✕ Think twice when…

    • Asking Copilot "is this correct?" as your only check.
    • Skipping human review because Copilot code review commented.
    • Pasting real customer data into a prompt to test a suggestion.

    ↔ Alternatives to consider

    • Rulesets or branch protection to make tests, scanning and human review required.
    • Copilot code review as an extra set of eyes, not a replacement for a person.
    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 accepts a GitHub Copilot suggestion for a function that calculates order discounts. What is the most reliable way to confirm that the function behaves correctly?

    Question 2

    Question 2 of 5

    A repository requires that AI-assisted code be checked for security vulnerabilities before it is merged. Which control should you add to the pull request workflow?

    Question 3

    Question 3 of 5

    A team adds GitHub Copilot as a reviewer on every pull request. The repository requires one approving review before merge. Which statement is true?

    Question 4

    Question 4 of 5 · Select 3

    Which THREE practices are part of operating GitHub Copilot responsibly?

    Question 5

    Question 5 of 5

    A developer uses the /tests command to generate tests for a Copilot-written applyDiscount function. All generated tests pass. In production, an unknown discount code returns NaN.

    What is the most likely reason the tests did not detect the defect?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner Why can't you just accept a Copilot suggestion if it compiles?

    Model answer

    Compiling only means the syntax is fine. Copilot predicts code, it doesn't run it, so the logic can still be wrong for some inputs, or it can be insecure. I read it, then I test it, especially with odd inputs.

    Intermediate Walk me through how you validate a function Copilot wrote.

    Model answer

    I read it line by line until I can explain it. Then I write or generate tests, including edge cases like an empty cart or an unknown discount code, and run them. The linter and type checks run too. In the pull request, code scanning and dependency review add another layer, and a teammate reviews it.

    Interviewer follows up

    Can Copilot write those tests for you?

    You

    Yes, /tests is a good start, but I review the tests too. If the same model wrote the code and the tests, they can share the same wrong assumption, so I add the edge cases I care about myself.

    Experienced developer What does "operate Copilot responsibly" mean day to day?

    Model answer

    Give it the right context so the output is better, keep secrets and real personal data out of prompts, never accept code I don't understand, keep the normal review and CI gates, give feedback with thumbs up or down, and be open in the pull request about where Copilot helped.

    Scenario Copilot generated a database query that passes all tests. A reviewer still blocks it. Why might they be right?

    Model answer

    Tests only cover what we thought to test. The query might build SQL from user input, which works in tests and is an injection risk in production. That's why code scanning and a human reviewer sit on top of tests.

    Architecture & design How do you stop unvalidated AI output from reaching main?

    Model answer

    Branch protection or rulesets on main: required pull request reviews from a person, required status checks for tests, lint and CodeQL, and dependency review. Copilot code review can add comments, but its review doesn't count as an approval, so a human still has to sign off.

    Quick revision

    Key points

    • AI output is a draft. It can be wrong, insecure, outdated or biased while looking confident.
    • Understand the code before you accept it.
    • Test it, with edge cases, and run the linter and type checks.
    • Code scanning and dependency review catch security problems tests miss.
    • Human pull request review stays, and Copilot code review doesn't count as an approval.
    • Responsible operation: good context, no secrets or personal data in prompts, feedback, transparency, ownership.

    Important terminology

    Validation
    Checking that AI output is correct, secure and fits your requirements before you use it.
    Edge case
    An unusual input, such as an empty list, a zero or an unknown code, where bugs often hide.
    Code scanning
    Automated analysis, for example with CodeQL, that finds security vulnerabilities and coding errors.
    Dependency review
    A pull request check that shows new or changed dependencies and known vulnerabilities in them.
    Linter
    A tool that flags style problems and likely bugs without running the code.
    Human review
    A person reads and approves a change before it merges.

    Common mistakes

    • Letting Copilot write both the code and the only tests, then trusting both.
    • Skipping review because "Copilot already reviewed it".
    • Accepting long suggestions with Tab without reading them.

    Exam tips

    • "Best way to confirm a suggestion is correct" = run tests (with edge cases), not "ask Copilot if it is correct".
    • "Find vulnerabilities in AI-generated code" = code scanning.
    • "Who decides to merge" = a person, after review and checks.

    Five quick revision questions

    1. 1.Does passing tests prove a suggestion is safe?Show

      No. Tests cover only what you thought of; add scanning and review.

    2. 2.Which chat command drafts tests for selected code?Show

      /tests.

    3. 3.Does Copilot code review count toward required approvals?Show

      No. It leaves comments; a person approves.

    4. 4.What should never go into a prompt?Show

      Secrets and real personal data.

    5. 5.What's the first validation step?Show

      Read the suggestion until you understand it.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: GitHub Copilot Plans: Free, Pro, Business and Enterprise

    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.