Skip to content
AI Agent & Markdown Files

Review AI-Generated Code for Security and Hidden Bugs

For when your AI agent wrote code that works, but you're not sure it's safe to ship. Paste the code or diff and answer six quick questions. It writes a REVIEW.md of specific findings tied to a file and line, each with how it breaks and the fix: missing ownership checks, keys in the browser bundle, unvalidated input, swallowed errors, risky dependencies and the edge-case tests the AI never wrote.

Illustration for the AI prompt: Review AI-Generated Code for Security and Hidden Bugs
Chat promptAI Agent & Markdown FilesClaudeChatGPTGemini
The Prompt
You are a senior application security engineer reviewing code that an AI coding agent wrote (Cursor, Claude Code, Copilot, Lovable, Bolt or a chat model). Treat it like a pull request from a fast junior developer: it probably runs, and it was optimized for working, not for safe. I need a review I can act on, saved as REVIEW.md in my project. Here is what goes wrong when I review this myself or ask an AI for a quick look: there is too much code and I feel like I'm missing things; the AI checks that a user is logged in but not that they own the record; API keys end up in a React component or a client bundle; auth tokens get logged with request headers; inputs go straight into queries; errors are caught and silently dropped; the tests only cover the happy path; and a generic review just tells me to "make sure permissions are correct" without saying where or how.

HARD RULES:
1. GROUNDED FINDINGS ONLY. Every finding names the exact file and line (or function, if there are no line numbers), quotes the problem code in a few words, says how it breaks or how someone would exploit it, and gives the concrete fix. No finding without a location. No generic advice like "validate inputs" or "follow best practices".
2. AUTHORIZATION FIRST. For every route, action, query or mutation that reads or changes data, check who is allowed to do it, not just whether someone is logged in. Look for missing ownership checks, cross-user and cross-tenant access, IDs taken from the request and trusted, and admin actions without a role check.
3. CHECK THESE EVERY TIME: secrets and API keys in code, client components, env vars exposed to the browser, or logs; tokens or passwords written to logs; input validation and injection (SQL, NoSQL, shell, path, HTML); CORS set to a wildcard; missing rate limiting or CSRF protection on login, signup and payment endpoints; webhook signatures not verified; SSL or certificate checks disabled; sensitive data stored in plain local storage; errors caught and ignored; hidden assumptions (a connection is always available, a list is never empty, a field is never null); dependencies that look outdated, unused or made up.
4. TESTS ARE CODE TOO. If I paste tests, check whether they only cover the happy path, and whether the AI changed tests or CI config to make them pass. List the boundary tests that are missing: logged-out access, another user's record, another tenant's record, bad or missing webhook signature, empty and oversized input, and the failure path of every outside call.
5. SEVERITY THAT MEANS SOMETHING. Use Critical (exploitable now, data or money at risk), High (likely bug or exposure), Medium (fragile, will break under real use), Low (cleanup). Don't pad the list with style nits; anything a linter would catch is not a finding.
6. NEVER INVENT. Only report what you can see in the code I paste. If something depends on code or config I didn't share (middleware, database rules, deploy settings), put it under CAN'T VERIFY instead of guessing. Don't claim a package has a known vulnerability; tell me to run the audit command for my package manager.
7. SAY WHAT'S CLEAN. List the areas you checked and found no problem, so I know what was actually covered and what wasn't.

BEFORE REVIEWING, ask me these in one short batch and STOP (skip any the pasted code already answers):
1. What does this code do, and who uses it (public users, logged-in customers, internal staff)?
2. Stack and framework, and what runs in the browser versus on the server.
3. The access rule in plain words: who should be able to see or change which records? Are there teams, tenants or roles?
4. Which outside services does it touch (payments, email, webhooks, an AI API, a database)?
5. What do you already run: lint, tests, type check, a dependency audit?
6. Paste the code or diff, plus any tests the AI wrote for it.

Then reply using exactly these sections:
VERDICT: one line: ship, ship after fixing Critical and High, or don't ship. Plus a count of findings by severity.
REVIEW.MD: the complete file in one markdown code block, with these headings:
# Code review: [feature name] (date under the heading)
## Findings: one table with columns # | Severity | Where (file:line) | Problem | How it breaks | Fix. Sort by severity, Critical first.
## Missing tests: one line per boundary test, written as the test name plus what it should assert.
## Checked and clean: the areas from rule 3 with no findings.
## Can't verify from this code: what to check elsewhere, such as deployed security headers, SSL, database rules or the dependency audit.
FIX ORDER: the 3 findings to fix first, one line each.
QUESTIONS: anything you need from me to confirm a finding you marked as uncertain.

Plain text outside the code block, no intro, no pep talk. End REVIEW.md with one line reminding me that this review is a second pair of eyes, not a replacement for reading and understanding what I merge.

Here are my details (fill in what you can, or leave blank and answer the questions):
What the code does: [FILL IN]
Stack: [FILL IN]
Access rule: [FILL IN]
Code or diff: [PASTE]

Start with the questions.
Open directly inChatGPTClaudeGemini

How to use this chat prompt

Paste it directly into a new chat, replace anything in [BRACKETS] with your context, and send. Re-use it whenever the task comes up, or save it as a text-expander snippet.

Example output

Cursor-built Next.js invoices API on Supabase, customers may only see their own invoices, code and tests pasted.

Plain ChatGPT answer

Overall the code looks clean and well structured.

Consider adding input validation and better error handling.

Make sure permissions are correct and keep your API keys secure.

With this prompt

VERDICT: ship after fixing Critical and High. 1 Critical, 2 High, 1 Medium.

REVIEW.MD: ## Findings | # | Severity | Where (file:line) | Problem | How it breaks | Fix |

| 1 | Critical | app/api/invoices/[id]/route.ts:14 | checks session, not owner | any customer reads another's invoice by changing the id | filter by user_id = session.user.id |

| 2 | High | lib/stripe.ts:3 | NEXT_PUBLIC_STRIPE_SECRET | secret key ships in the browser bundle | move to a server-only env var and rotate the key |

## Missing tests: GET another user's invoice returns 404; logged-out request returns 401.

## Can't verify from this code: Supabase row level security, npm audit.

FAQ

Frequently asked questions

How do you review AI-generated code?

Review it like a pull request from a fast junior developer. Run lint, tests and a dependency audit first, then read for what the AI was never asked to care about: who is allowed to touch each record, where secrets end up, what happens on bad input and whether the tests go beyond the happy path. Smaller changes are much easier to review, so it helps to build in small steps with a vibe coding build plan and review each one before you merge it.

Is AI-generated code secure?

Not by default. Coding agents optimize for code that works for the request you gave, and security is rarely part of that request. Developers who vibe code often report the same misses: a login check with no ownership check, API keys in client components, wildcard CORS, tokens written to logs and no rate limiting on login. The code can run perfectly and still be unsafe to ship.

Can AI review code for security vulnerabilities?

It can catch a lot when you explicitly ask it to, which is what this prompt does: it forces a file and line for every finding and a list of what it checked. It can't see your deployed site, your database rules or code you didn't paste, so those go under a separate can't-verify section. Treat it as a second pair of eyes, not a replacement for reading the code yourself.

What is a good prompt for code review?

One that names what to check, demands a location for every finding and bans generic advice. Vague prompts get vague answers like "make sure permissions are correct". This one asks about your access rules first, sorts findings by severity, lists missing boundary tests and saves everything as REVIEW.md so you can track fixes. If the same mistakes keep coming back, put the rule in a file made with the AGENTS.md generator so the agent sees it every session.

Should I review with a different AI model than the one that wrote the code?

Many builders do, because a second model is less likely to share the first one's blind spots, and the same goes for tests the AI wrote for its own code. This prompt works in ChatGPT, Claude or Gemini, so you can run it in a different model from your coding agent. It still won't catch everything, so merge only what you understand.

Keep going

What's next