AI-Assisted Engineering

How to Review AI-Generated Code Like a Senior Engineer

Google has said more than a quarter of its new code is now AI-generated, then reviewed and accepted by engineers. As AI writes more code everywhere, code review becomes the key quality and security control. This is a practical guide to reviewing AI-generated code: what to look for, in what order and how to scale review without burning out.

By EthicalHat Research · · 3 min read
Infographic: A senior engineer's review order for AI code

In October, Google told investors that more than a quarter of all new code at Google is generated by AI, then reviewed and accepted by engineers. Across the industry, the share of AI-assisted code is growing fast. That makes code review, always important, the central control for quality and security.

Reviewing AI-generated code is not quite the same as reviewing a colleague's. The failure modes are different, and the volume is higher. Here is how experienced engineers approach it.

Start with intent, not syntax

AI-generated code is usually syntactically clean, well formatted and plausibly named. That surface polish can pull reviewers into line-by-line reading before they have asked the most important questions:

  • Does this solve the problem described in the ticket, or a slightly different one?
  • Is this the right place in the codebase for this logic?
  • Is this the simplest approach, or did the assistant build more than needed?
  • Should this code exist at all, or does something similar already exist?

If the answer to any of these is wrong, line-level review is wasted effort.

Know the characteristic failure modes

AI-generated code tends to go wrong in predictable places. Check them deliberately:

Failure modeWhat to look for
Happy-path biasMissing handling for empty inputs, nulls, timeouts, partial failures
Swallowed errorsBroad except/catch blocks, errors logged and ignored
Invented APIsMethods or parameters that do not exist in your library version
Outdated patternsDeprecated APIs, old framework idioms
Security gapsMissing authorisation, unsanitised input, disabled TLS verification, secrets in code
DuplicationA new helper that duplicates an existing one
Tests that test nothingAssertions mirroring the implementation, mocks that bypass the logic under test
Over-engineeringAbstractions, options and configuration nobody asked for

A classic example that passes a quick glance:

python
def get_invoice(request, invoice_id):
    try:
        invoice = Invoice.objects.get(id=invoice_id)       # no ownership check (IDOR)
        return JsonResponse(invoice.to_dict())
    except Exception:                                      # hides real failures
        return JsonResponse({"error": "not found"}, status=404)

What a senior reviewer asks for:

python
def get_invoice(request, invoice_id):
    invoice = get_object_or_404(
        Invoice, id=invoice_id, account=request.user.account   # scoped to the caller
    )
    return JsonResponse(InvoiceSerializer(invoice).data)        # explicit fields only

Review the tests as hard as the code

AI is very good at producing tests that pass. That is not the same as tests that would catch a bug. Check that:

  • expected values come from requirements, not from running the code,
  • negative cases and boundaries are covered,
  • mocks do not replace the very behaviour being tested, and
  • the tests would fail if the implementation were wrong. Mutation testing helps here.

Let automation do the mechanical work

Human attention is the scarce resource. Before a person reviews anything, automation should have checked:

  • formatting, linting and type checking,
  • unit and integration tests,
  • SAST, dependency and secret scanning,
  • new dependencies flagged for explicit approval, and
  • duplication and complexity thresholds.
flowchart LR
  PR[AI-assisted PR] --> A[Automated gates<br/>tests, types, lint,<br/>SAST, SCA, secrets]
  A -->|fail| Back[Back to author]
  A -->|pass| H[Human review<br/>intent → behaviour →<br/>security → fit]
  H -->|risky paths| S[Second reviewer<br/>security / code owner]
  H --> M[Merge]
  S --> M

Keep diffs reviewable

AI makes large diffs cheap to produce and expensive to review. Set team norms:

  • keep pull requests focused on one change,
  • split generated refactors from behaviour changes,
  • reject diffs too large to review properly, rather than skimming them, and
  • ask authors to explain in the description what the AI generated and what they changed or verified.

Apply risk-based depth

Not every change needs the same scrutiny. Spend the most attention on:

  • authentication, authorisation and session handling,
  • payments and financial calculations,
  • data access and privacy-sensitive code,
  • database migrations and infrastructure changes, and
  • concurrency and anything performance-critical.

Code-owner rules can route these paths to a second reviewer automatically.

Protect the reviewer

Review fatigue is a real risk when AI multiplies the volume of code. Rotate reviewers, limit review sessions, and treat time spent reviewing as real engineering work, not an interruption to it.

The bottom line

As more code is written by AI, the engineer's most important contribution shifts towards judging it: whether it solves the right problem, handles the real world, keeps data safe and fits the system it joins. Review with that order of priorities, let automation handle the rest, and keep changes small enough to review honestly.

Our secure code review service provides expert review of AI-assisted codebases, and our security training teaches development teams these review practices.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.