---
title: Reviewing and verifying AI output
summary: How to check what an agent hands back, with evidence instead of confidence, small diffs, tests that can fail and a sharp eye for invented dependencies.
section: ai
phase: verify
order: 5
last_reviewed: 2026-11-20
---

# Reviewing and verifying AI output

Agent output reads well, compiles often and sounds sure. None of that is evidence. Your job is to turn "looks right" into "proved right" before anything ships.

## You'll be able to

- Give an agent a check it can run, and insist on seeing the real output
- Review a diff in a sensible order, and know what to look for
- Tell whether tests would actually catch a bug
- Catch invented or risky dependencies before they get installed
- Decide when to correct, when to split the work, and when to throw a result away

## The mental model

Treat the agent like a fast, confident colleague who never tires and sometimes bluffs. You wouldn't merge their work on their say-so. You'd read the diff, run it, and ask for proof. The skill is making that cheap: define a pass-or-fail check up front, keep each change small enough to read, and look at evidence rather than summaries.

Anthropic's best-practices guide for Claude Code puts the first step plainly: give the agent something it can run that comes back pass or fail, such as a test file, a build's exit code, a linter, a script that compares output to a known result, or a screenshot next to a mockup.

## Key concepts

- **Evidence over claims:** "All tests pass" is a claim. The command and its full output are evidence. Ask for the evidence.
- **A check that can fail:** A test is only useful if it fails when the code is broken. Google's code review guidance says to check exactly that, and notes that tests are code you have to maintain too.
- **Small batches:** Google's guidance recommends small, self-contained changes: easier and quicker to review, less likely to hide bugs, easier to roll back. It gives about 100 lines as a reasonable size and about 1,000 as usually too large, and it counts spread across many files too. Refactoring belongs in its own change.
- **Review dimensions:** Google's guide lists what a reviewer looks at: design (does it belong here), functionality, complexity (including over-engineering), tests, naming, comments, consistency with the codebase, and documentation. It also says to look at the context around the diff and not to accept changes that degrade code health. It was written for human reviews, and it applies just as well to agent diffs.
- **Scope creep:** The diff touches more than the request needed. Common with agents, and the first thing to look for.
- **Package hallucination:** A model recommends a dependency that doesn't exist. A paper analyzing 576,000 code samples from 16 models (abstract, v3, 2025) reports hallucinated packages in at least 5.2% of cases for commercial models and 21.7% for open-source models, and calls the result a package confusion attack: if someone registers a name that models tend to invent, you could end up installing code they control. People sometimes call this slopsquatting.
- **Fresh-eyes review:** A second pass by a reviewer that hasn't seen the original reasoning (a new session or a subagent). The Claude Code guide recommends this, and warns against blindly "fixing every finding" from a reviewer that was told to find problems.
- **Checkpoints:** Commit after each verified step so a bad step is easy to undo.

## Decisions you make (not the agent)

| Decision | Sensible default | Choose otherwise when… |
|---|---|---|
| How deep to review | In proportion to risk: auth, payments, data changes and migrations get a full read | Copy edits and trivial changes get a quick scan |
| Change size | One self-contained change, around 100 lines | Mechanical, well-tested changes (a rename) can be larger |
| What counts as proof | Command plus full output, run by the agent and re-run by you for important changes | Throwaway prototypes |
| New dependencies | Don't add any without asking. When one is needed, verify it exists, what it does, who maintains it and why existing code can't do the job | The project already uses it |
| Tests | Required for behavior changes, and you check they can fail | Pure formatting or docs changes |
| Second opinion | A fresh-context review for risky changes, with "skip style nits" | Small low-risk diffs |
| When to discard | After two failed corrections, restart with a better prompt rather than a third patch | The fix is one obvious line |
| Merge | Only after you've read the diff yourself | Never skip, however long the task ran |

## What good output looks like

- The agent shows the command it ran and the real output
- The diff is small and every changed file relates to the task
- New tests fail when the behavior is removed
- No new dependency, or a single one that is named, justified and real
- No existing test was weakened, skipped or deleted
- Assumptions and unfinished parts are stated up front

## Red flags

- **"All tests pass" with no output** → ask for the command and the full result, and run it yourself.
- **A test was edited to make it pass** → read the test diff first. A changed expectation is a changed requirement.
- **Tests that mock everything** → they may never touch the real code path. Break the code on purpose and see if they notice.
- **Unrelated files changed** → scope creep. Reject, or ask for a split.
- **A dependency you don't recognize** → check that it exists, what it does, and when it was published, before installing.
- **A sweeping rewrite for a small request** → reject and re-prompt narrowly.
- **A broad try/catch that swallows errors** → failures become silent.
- **Hardcoded values that satisfy the test** → ask for a general solution and add different test inputs.
- **A reviewer agent with twenty findings that you apply wholesale** → triage them. Many will be style or speculation.

## Worked example

**Task:** Add a "cancel booking" endpoint to a Next.js and Postgres app.

The agent returns a 600-line diff and says: *"Done. All tests pass."* It reads like a finished feature.

**What a good result contains:** a small change (one route handler, one query, a few tests); an ownership check so users can only cancel their own bookings; a clear response when the booking is already cancelled; and tests that fail if any of those are removed.

**The wrong turn:** the diff also reformats three unrelated files, edits an existing test's expectation so it matches the new behavior, and the new test mocks the database layer, so the real cancellation query is never run. Everything is green and nothing is proved.

**How review catches it:** look at the diff stats and the list of changed files before reading any code. Read the test changes first: one existing assertion changed, and the new test never touches the database. Then run a quick sabotage check: remove the ownership check, re-run the tests, and see whether anything fails (it doesn't). Ask the agent for a smaller change with a real integration test, run against a test database, that would fail without the check.

## Sample prompts

### Weak vs strong
```compare
## Weak
Review my changes and tell me if they're good.
## Why it fails
No criteria, no scope, no evidence required. You'll get a pleasant summary.
## Strong
Act as a skeptical reviewer. Compare this branch to main and review only the diff.
Check, in this order: design (does this belong here), functionality against the stated goal: <goal>, complexity and over-engineering, tests (would they fail if the code were broken?), naming and consistency with nearby code, and documentation.
Report findings with file and line, ranked by severity. Say "no issue" for any area that is fine. Do not change any code. Skip style nits.
## Why it works
It gives an ordered checklist, forbids edits, asks for locations and severity, and filters out noise.
## What changed
- **A role and an order of checks** replace 'is it good?'
- **Evidence is required**: file and line, ranked by severity
- **No edits yet**, so review and fixing stay separate
- **Style nits are excluded** to reduce noise
```

### Require evidence
```text
Before you say this is done, show me evidence, not a summary: the exact commands you ran (lint, typecheck, tests) and their full output. If any command wasn't run, say so plainly. Then list what you did not verify.
```
*Why it works:* It replaces "all tests pass" with output you can check, and surfaces gaps honestly.

### Check that the tests can fail
```text
Break the implementation on purpose in three different ways (for example, remove the ownership check, flip a comparison, return early). After each change, run the tests and record whether they failed. Then revert everything. Report which breakages the tests did NOT catch and propose tests that would.
```
*Why it works:* A test that can't fail proves nothing, so this shows you which ones are decoration.

### Vet new dependencies
```text
List every new dependency this change introduces (check package.json and the lockfile). For each: what it does, why existing code or the standard library isn't enough, and the exact command I can run to confirm that it exists and who publishes it. Don't install anything. Flag any you are not certain exist.
```
*Why it works:* It forces a justification and gives you a way to verify, which addresses invented packages directly.

### Audit the scope
```text
List every file changed in this diff and, in one line each, how it relates to the task: <task>. Flag anything unrelated. Propose how to split this into separate commits (feature, tests, refactors) so each can be reviewed and reverted on its own.
```
*Why it works:* It exposes scope creep and turns one big diff into reviewable pieces.

### Restart cleanly
```text
We've tried to fix this twice and it still fails. Summarize what the problem is, what we've tried and why each attempt failed, and the constraints we've learned. Then write one better prompt I can use to start a fresh session.
```
*Why it works:* After repeated failed corrections, a clean start with what you've learned usually beats a third patch on a muddied context.

## Check your understanding

```quiz
Q: The agent says "All tests pass." What should you ask for?
- [ ] Nothing, that is evidence
- [x] The command and its full output, which you can re-run yourself
- [ ] A longer summary
> Why: "All tests pass" is a claim. Output from a command you can run is evidence.

---

Q: How can you tell whether a test is worth having?
- [ ] It has a long name
- [x] Break the code on purpose and see whether it fails
- [ ] Count its assertions
> Why: A test that can't fail proves nothing. Mutation testing automates this idea.

---

Q: You get a 600-line diff for a small task. What do you look at first?
- [ ] The last file
- [x] The list of changed files, and the test changes
- [ ] The commit message
> Why: Unrelated files and edited expectations are the fastest signs of scope creep and tests changed to pass.

---

Q: An agent adds a dependency you have never heard of. What do you do?
- [ ] Install it
- [x] Check that it exists, what it does and who publishes it, before installing
- [ ] Trust it because the agent chose it
> Why: Models can invent package names, and attackers can register them.
```

## Checklist

- [ ] The prompt included a check the agent could run (pass or fail)
- [ ] I saw the actual commands and output, not just "done"
- [ ] The diff is small and every file relates to the task
- [ ] I read the test changes first, and no test was weakened
- [ ] I confirmed the tests can fail
- [ ] Every new dependency exists, is needed and was justified
- [ ] I ran it myself for anything risky
- [ ] Committed a checkpoint before the next step

## Go deeper

- [We Have a Package for You! (arXiv 2406.10279)](https://arxiv.org/abs/2406.10279): the study of package hallucinations in code-generating models; figures above are from the abstract of the 2025 revision
- [Best practices for Claude Code](https://code.claude.com/docs/en/best-practices): giving the agent a pass-or-fail check, asking for evidence, and restarting after failed corrections
- [What to look for in a code review (Google)](https://google.github.io/eng-practices/review/reviewer/looking-for.html): design, functionality, complexity, tests and more
- [Small CLs (Google)](https://google.github.io/eng-practices/review/developer/small-cls.html): why small changes are easier to review and revert
- [Security of agentic workflows](/docs/ai-agents/agent-security.md): when the risk is the agent itself, not just its output
- [Testing](/docs/quality/testing.md): what good tests look like in this stack
- [Working with coding agents](/docs/start-here/working-with-coding-agents.md): the verification habits in the agent loop
- [How LLMs work, for builders](/docs/ai-agents/how-llms-work.md): why plausible output can be wrong
