To review AI-written code, clarify the requirement, trace inputs to outputs, verify server-side authorization, run existing checks, add a test that reproduces a failure, and inspect the corrected diff. Use the model to help explain the code; establish behavior through code inspection and executed checks.
1. Define acceptance before reviewing
A successful demo is one case. Write the input, expected behavior and evidence for the change you are reviewing.
| Check | What to inspect | Evidence to retain |
|---|---|---|
| Requirements and scope | Does the diff solve the task without extra features, lost constraints or deleted tests? | Acceptance notes and Git diff |
| Inputs and outputs | What happens with valid, empty, missing, wrongly typed and oversized inputs? | Expected and actual results |
| Authorization and data | Who may read or modify a record? Are identity and ownership checked on the server? | Allowed and denied cases |
| Dependencies and APIs | Do the package and API exist? Do versions, licenses and configuration fit? | Official references and lockfile diff |
| Failures and side effects | Could timeouts, retries or duplicate submissions repeat a write? | Reproduction and state readback |
| Regression and delivery | Does the counterexample fail before the fix and pass after it? Is existing behavior preserved? | Commands, results and known limits |
Example: working code lets another user read a document
This original local exercise uses two fictional records. The contract is: a user may read only their own document; deny missing or unauthorized records. Review this deliberately incorrect implementation:
Python · review_example.py · incorrect example
DOCUMENTS = {
"doc-a": {"owner": "alice", "text": "Alice notes"},
"doc-b": {"owner": "bob", "text": "Bob notes"},
}
def read_document(user_id, document_id):
return DOCUMENTS[document_id]["text"]
read_document("alice", "doc-a") returns the expected text, but read_document("bob", "doc-a") returns Alice's text too. Accepting a user_id parameter is not the same as checking authorization. Hiding a button cannot fix this server-side disclosure.
The exercise assumes user_id comes from an authenticated server session. A real endpoint must not trust a user ID supplied in the request body. This dictionary does not model a production database, organization permissions or concurrency.
Small fix: verify ownership before returning the text
Save this as review_example.py. Missing and unauthorized records use the same denial, so the error does not distinguish whether another user's record exists.
Python · review_example.py
DOCUMENTS = {
"doc-a": {"owner": "alice", "text": "Alice notes"},
"doc-b": {"owner": "bob", "text": "Bob notes"},
}
def read_document(user_id, document_id):
document = DOCUMENTS.get(document_id)
if document is None or document["owner"] != user_id:
raise PermissionError("document unavailable")
return document["text"]
Four runnable tests
Save this as test_review_example.py in the same directory. Use Python 3; only the standard library is required. No installation or external service is involved.
Python · test_review_example.py
import unittest
from review_example import read_document
class DocumentReviewTests(unittest.TestCase):
def test_owner_can_read(self):
self.assertEqual(read_document("alice", "doc-a"), "Alice notes")
def test_other_user_cannot_read(self):
with self.assertRaises(PermissionError):
read_document("bob", "doc-a")
def test_missing_document_is_denied(self):
with self.assertRaises(PermissionError):
read_document("alice", "missing")
def test_empty_document_id_is_denied(self):
with self.assertRaises(PermissionError):
read_document("alice", "")
if __name__ == "__main__":
unittest.main()
Run in that directory:
python3 -B -m unittest -v test_review_example.pyThe fixed version should report Ran 4 tests and OK. Replace the function with the incorrect version above: the cross-user assertion fails, while the missing and empty IDs raise unexpected errors. The tests distinguish the contract from the implementation.
These four cases cover only this reading contract. They do not establish security for an arbitrary application. Review authentication, input types, database queries, idempotent writes, logging and the runtime as the real task requires.
Review dependencies and delivery evidence
- Inspect the Git diff for configuration changes, removed tests and unverified dependencies. Check APIs and versions against official documentation before installing a generated package suggestion.
- Run existing formatting, type, build and relevant test checks, then add counterexamples that distinguish correct behavior from a plausible mistake. Obtain independent human review for permission changes or external side effects.
- Record the change, reproduction steps, actual commands, results and untested scope. A model approval or one passing test is not complete acceptance.
A reusable review request
Review only the current diff. Restate the requirement and trust boundaries. For each reproducible issue, name the file and line, failing input, expected result, smallest fix and verification command. Separate executed checks from untested assumptions. Do not delete failing tests, extend scope, or read or print credentials.
Common questions
Can AI review code it generated?
Use it to explain data flow, suggest counterexamples and organize checks. Independently verify official APIs, run tests and judge the business contract. Another model response is not execution evidence.
Is this a detector for AI-written code?
No. This guide checks requirements, permissions and edge cases. It does not identify authorship. The origin of code cannot establish its quality.
Should I ship code I cannot explain?
Reduce the change to a scope you can understand, practice with the local exercise, and get qualified review for authorization, payments or external writes. Passing tests do not replace understanding the impact.
Next: apply the checklist to a learning task
The free AI coding course includes requirements, boundary checks and small-change exercises. Continue with retrieval and citations in a knowledge base, or tool permissions and workflow recovery.
References and exercise scope
The process draws on official references; the exercise and tests are original. This is not an official GitHub course or a security certification.
Content updated: 2026-10-23