Validate Copilot Output and Use It Responsibly
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 neededExam 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.
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
- Copilot suggests a function that looks right. Before you press Tab, ask: what happens with an unknown code?
- Test it. A quick test with an edge case shows the suggestion returns NaN. Running code beats reading it.
- 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.
- 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.
🖱️ Drag to rotate · scroll or pinch to zoom
Ghost text: accept or reject
The suggestion appears as grey ghost text. Tab accepts, Esc dismisses, Alt+] / Alt+[ cycle alternatives, Ctrl+→ accepts word by word. You decide what goes into your code.
🤔 What happens if…
Read this tour as text
- You type, then pause. Copilot doesn’t read your mind. When you pause while typing, the Copilot extension in your IDE starts a request for a completion.
- The IDE builds a prompt. The extension gathers context: code before and after the cursor, the file name and language, and related snippets from other open tabs. That bundle is the prompt. A model has a limited context window, so the extension picks what matters most.
- Content exclusions are checked. An admin can exclude paths or whole repositories. Excluded files are not used as context, and Copilot gives no inline suggestions inside them.
- The Copilot proxy. The prompt goes over HTTPS to a GitHub-hosted proxy. It authenticates the request and runs pre-filters, for example for harmful or offensive content and prompt-injection attempts, before anything reaches the model.
- The model predicts code. A large language model predicts the most likely next tokens. It matches patterns from training data and your context; it doesn’t run, test or truly understand your code. That’s why output can be wrong, outdated or insecure.
- Post-processing filters. Before you see it, the response is post-processed: checks for code quality and common insecure patterns, offensive content, and (if your policy says Block) a check for matches with public code of about 150 characters or more.
- Ghost text: accept or reject. The suggestion appears as grey ghost text. Tab accepts, Esc dismisses, Alt+] / Alt+[ cycle alternatives, Ctrl+→ accepts word by word. You decide what goes into your code.
- What data is kept. Prompts and suggestions are encrypted in transit. For Copilot Business and Enterprise, your code is not used to train GitHub’s models, and prompts and suggestions from IDE code completion are not retained after the response. Engagement data (accepts, rejects, errors) is kept to run and improve the service and to power usage metrics.
Let Copilot write a script and tidy files, but on your terms. Run one prompt non-interactively, see why it stops, give it exactly the permissions it needs and block the ones it doesn't.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 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
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.
Read the video script
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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 Read
Understand every line. If you cannot explain it, ask Copilot to explain it, then check that against the code.
-
2 Test
Run existing tests and add edge cases: empty input, zero, unknown values, very large numbers.
-
3 Lint and type check
Let the linter and type checker flag likely bugs and unknown symbols.
-
4 Scan
Code scanning finds vulnerabilities; dependency review checks any new packages.
-
5 Human review
A teammate reviews the pull request. Required checks must pass before 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
| Habit | Why |
|---|---|
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 prompts | Prompts leave your machine; use fake sample data |
| Never accept code you don’t understand | You can’t review or maintain what you can’t explain |
| Keep pull request review, CI and branch protection | Copilot speeds up writing, it doesn’t replace the gates |
| Give feedback with thumbs up or down | It helps GitHub improve responses |
| Say when Copilot helped | Reviewers 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
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.
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 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.Does passing tests prove a suggestion is safe?Show
No. Tests cover only what you thought of; add scanning and review.
-
2.Which chat command drafts tests for selected code?Show
/tests.
-
3.Does Copilot code review count toward required approvals?Show
No. It leaves comments; a person approves.
-
4.What should never go into a prompt?Show
Secrets and real personal data.
-
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
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.