BlogAI

AI Code Review and AI Output: When to Trust It, When to Verify, When to Rewrite

AI review is useful, but right and wrong answers arrive in the same confident tone. Where it shines, how it fails, and a workflow for checking it.

Denny Pratama

16 Jun 2026 · 9 min read · AI

AI Code Review and AI Output: When to Trust It, When to Verify, When to Rewrite

01Useful, But Not a Safety Net

Routing code through an AI review step before committing has real benefits. Spotting a missing htmlspecialchars() call, catching an n+1 query you glazed over, suggesting a more readable way to chain array operations: an AI reviewer does all of that fast, and without the social overhead of asking a colleague for a review on a Saturday afternoon.

But "use AI" and "trust AI blindly" are two very different things. The problem isn't that AI gives bad advice. It's that bad advice and good advice arrive in the same confident, well-formatted tone. There's no hesitation in the output to signal that you should slow down.

This post isn't a takedown of AI-assisted review. It's about calibration: knowing when to trust the output and when to treat it as a confident first draft from a junior developer who has read a lot but deployed very little.

02Where AI Review Is Genuinely Good

There are categories of feedback where AI review is consistently strong:

  • Security surface scanning: It reliably catches unescaped output, user input passed straight to SQL or shell commands, missing CSRF token checks, and loose file permission assumptions. These are pattern-recognition tasks, and LLMs are pattern machines.
  • Readability and naming: It has no ego about your variable names. It will tell you $d is a bad name for a date object every single time.
  • Documentation gaps: Paste in a function with no docblock and ask what a new developer would misunderstand. The answers are usually accurate and humbling.
  • Obvious logical errors: Off-by-one errors, inverted conditionals, unreachable branches, the kind of thing you stop seeing after staring at the same function for an hour.

The same goes beyond code. Creative and structural output (UI copy, placeholder content, boilerplate, outlines, first drafts) is where AI is most dependable, partly because it's so quick to check.

03How It Goes Wrong, and Why It's Hard to Catch

Picture a file upload validator that checks both MIME type and extension:

$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($_FILES['upload']['tmp_name']);
$allowed = ['image/jpeg', 'image/png', 'image/webp'];

if (!in_array($mime, $allowed)) {
    throw new RuntimeException('Invalid file type.');
}

$ext = strtolower(pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION));
$allowed_ext = ['jpg', 'jpeg', 'png', 'webp'];

if (!in_array($ext, $allowed_ext)) {
    throw new RuntimeException('Invalid file extension.');
}

Say the AI suggests consolidating this into a single validation function to "reduce duplication". Its version checks the MIME type correctly. On its own, a filename with no dot makes pathinfo() return an empty string, which isn't in $allowed_ext, so the extension check would still fail as it should. But in the refactor, the extension check has quietly moved inside an if block that only runs when a specific condition is met. Files without extensions slip through.

The change is framed as a simplification, and the explanation is convincing. That explanation is the trap. In review mode you read it the way you read a finished argument, looking for obvious flaws rather than tracing every execution path.

This is the core danger: AI output shifts you from a generative mindset to an evaluative one, and evaluative reading is shallower than generative writing. You're approving, not building.

04The Common Failure Modes

1. Context blindness

The AI sees what you paste. It doesn't see the calling code, the database schema, your hosting environment's quirks, or the business rule that explains why something that looks redundant is actually load-bearing. It will confidently remove "redundant" checks that exist because of an edge case someone discovered months ago and never commented.

The same applies to server-side behavior. A model can describe PHP session behavior in a way that's correct for a standard server but wrong for shared cPanel hosting with a custom session.save_path. It doesn't know your host or your php.ini. Treat anything involving file system paths, PHP configuration, cron syntax or .htaccess rules as a starting point, not an answer.

Rule: Anything the AI flags as redundant gets a manual trace through the full call chain before removal.

2. Framework and version assumptions

If you target environments where you don't control the PHP version, AI suggestions that are clean and correct in PHP 8.2 can be syntax errors on a shared host still running 7.4. Models know modern idioms well; they're less reliable about what degrades gracefully.

Rule: Check any suggested function against the PHP version shown in phpinfo() before accepting it.

3. Security theater

AI review sometimes adds the appearance of security without the substance. Say it suggests sanitizing a value that's about to be passed to password_hash(). That's harmless, but it implies sanitization is the right model for password handling, when the point is to hash the raw input. The code gets harder to reason about, not safer.

Rule: Evaluate security suggestions against the actual threat model, not whether they pattern-match to "safe-looking code".

4. Confident answers on obscure APIs

Ask it to review code that talks to a niche cPanel API endpoint or a specific payment gateway's webhook format, and it may review against an API version or behavior it has reconstructed from incomplete training data. It won't tell you it's guessing.

Rule: Anything touching third-party APIs gets cross-checked against the current official documentation.

5. Dependencies you didn't ask for

Models lean toward solving problems with libraries. Ask for a date formatter in vanilla JS and the output may import Moment.js or suggest date-fns. Ask for an animation and GSAP appears. Ask for a chart and Chart.js is assumed. On shared hosting with no build pipeline, every extra library is another file or CDN dependency to manage.

Rule: Flag anything that introduces a dependency you didn't ask for, and decide whether it's actually needed.

05A Workflow for Checking AI Output

None of these steps means distrusting AI across the board. They're about knowing where to move fast and where to slow down.

  1. Ask whether you can verify it in under 60 seconds. If you can confirm the output by looking at it, running it, or checking a known source in under a minute (UI copy, placeholder text, list formatting, HTML structure), use it. Session logic, SQL optimization, file permissions and CSRF handling are not quick to verify, and that's where AI gets things subtly wrong.
  2. Separate creative from functional output. For creative work you're judging tone, fit and clarity: fast, subjective, low-stakes. For anything that runs, queries, authenticates or renders dynamically you're judging correctness, edge cases and security: slow, objective, high-stakes. The mistake is reviewing functional output at creative-output speed.
  3. Treat high confidence as a yellow flag. Fluent, decisive output is evidence that the model has seen a lot of text like this answer, not that it's correct. The dangerous outputs aren't the obviously wrong ones; they're the confident, subtly wrong ones: a SQL query that works most of the time but breaks on NULL comparisons, an event listener that behaves differently in Safari, a regex that almost handles the edge case.
  4. Give it the context it can't see. PHP version, hosting constraints, the business rule the function enforces. The more context, the less room for bad assumptions.
  5. Make sure you could explain every step. Not "does it look right" but "could I explain each line to someone else?" If there's a block you're skimming because it looks plausible, rewrite that section yourself or break it into smaller pieces you can prompt separately.
  6. Use a second prompt to break the first output. Follow up with "What are the edge cases where this could fail?", "What assumptions does this code make that might not be true?" or "If someone was trying to break this, where would they start?" It's not perfect, and sometimes it just reassures you, but it surfaces blind spots often enough to be worth it, especially for security-adjacent code.
  7. Rewrite structural refactors yourself. When the AI suggests reorganizing logic, use its suggestion as a statement of intent and write the code yourself, rather than applying it as a patch. That puts you back in generative mode.
  8. Run the "would I write this differently?" test. Not "is this wrong?" but "would I have written it differently?" If yes, even when you can't say why yet, rewrite it. That instinct is worth trusting.
  9. Treat security-adjacent output as unverified until tested. File uploads, authentication, sessions, CSRF tokens, SQL parameters, input sanitization: test all of it manually, even when it looks textbook correct. These are the areas where code works, passes a basic review, and then fails under one specific edge case.
  10. Finish with a manual execution trace. Pick the two or three most significant changes and walk every input through every branch. Not a skim. An actual trace.
  11. Keep a failure log. Each time an AI output causes a bug or a wasted hour, write down the category. Not to blame the model, but to find your own patterns: are you trusting SQL too quickly, or skipping the second-prompt check when you're rushing? Over time it makes the failure modes much faster to recognize.

06The Honest Assessment

AI-assisted review is a productivity tool, not a safety net. Treating it as a safety net is where people get into trouble. Its strength is compressing the time spent on mechanical review, so you can spend more attention on what only you can evaluate: the business logic, the deployment context, the edge cases that only show up in your system.

The AI is a fast, well-read collaborator with no memory of your specific system and no skin in the game when it ships. Keep that picture in mind every time you read its output.

The people who get the most out of these tools aren't the ones who trust them most. They're the ones with an accurate picture of where the tools fail, who lean hard on them for creative output, boilerplate and drafts, and apply real judgment to environment-specific logic, security and edge cases.

07Frequently Asked Questions

How do I know when an AI output is safe to use without manual verification?

If the output is purely structural or creative (formatting, copywriting, placeholder content) and you can check it by eye in under a minute, it's usually safe to use with minor edits. For anything touching logic, security, or data, always verify against documentation or run it through your own tests before shipping.

Does the model matter, or are these patterns universal?

The patterns apply across models, but the failure modes can differ. Some models explain their reasoning more, which makes errors easier to spot; others sound just as confident when they're wrong. Knowing how your model tends to fail helps you calibrate how much skepticism to apply.

What's the biggest mistake people make when evaluating AI outputs?

Trusting fluency as a proxy for correctness. AI outputs often sound precise and authoritative even when they're wrong. A well-structured, confidently written response doesn't mean the logic is sound, especially with server-side behavior, edge cases, or security-sensitive code.

AI

Denny Pratama

Product designer in Indonesia. Since 2018 I’ve designed SaaS products, dashboards and marketing sites, and now I build my own designs too.

About me