Prompt Engineering AI-Generated Code Code Review

Review AI-Generated Code

AI wrote it; review it with extra suspicion: strict correctness review of the diff, because generated code fails confidently.

Overview

AI-generated code has a signature failure mode: it looks right. It compiles, reads cleanly, handles the happy path — and invents an API, drops an edge case, or quietly changes behavior it wasn't asked to touch. This setup reviews AI-generated changes as diffs under strict correctness: the twelve correctness checks plus diff criteria (does the change do ONE thing? is changed behavior covered by changed tests? what's the regression risk in touched paths?), with every finding flagged and the verdict withheld until the checklist is done.

Workflow

  1. Review the diff, not the file

    Diff scope flags unrelated changes — the assistant's favorite way to expand its own scope.

  2. Verify every external call

    Invented APIs are the signature AI failure: each external symbol the diff introduces deserves a checklist pass.

  3. Demand changed tests for changed behavior

    The diff criterion that catches the silent behavior change generated code loves to slip in.

Why This Works

  • Strict style removes the benefit of the doubt that fluent code unearns
  • Diff criteria catch scope expansion — the AI failure mode reviews built for humans miss
  • One review contract scales to whatever volume the assistant produces

Best for

  • Teams adopting AI coding agents with a review gate
  • Diffs accepted under time pressure from a confident assistant
  • Codebases where generated code volume outpaces human review

Not for

  • Validating AI output FORMAT (JSON, structure) — that's the AI Output Validator
  • Re-generating the code — review the diff that exists; regeneration re-rolls the risk

Use cases

  • Gating Copilot/agent-written changes before they enter the codebase
  • Catching the invented API call that compiles against nothing
  • Flagging the unrequested "improvements" hiding in the diff

Tip: Save time by exploring related resources and tools that integrate with this workflow.

Explore all resources