Understand & Verify AI Responses
Code from AI doesn't equal "production-ready." Learning to read, question, and validate is what turns AI into a reliable partner instead of a liability.
Read Structure Before Details
- Look at function signatures, dependencies, and edge case handling first. Decide whether it actually fits your project.
- Flag anything you're unsure about (types, interfaces, error handling) and prepare follow-up questions.
Make AI Self-Check
Review the code you just generated. List 3 scenarios where it might fail and suggest fixes for each.
If there are performance concerns or unhandled exceptions, call those out too.
Handing the "QA" step back to AI is a quick way to surface things it missed.
Have It Write Tests
Write 4 unit tests for the function above, covering: empty input, duplicate input, invalid input, and the happy path.
Use the test framework already in the project (Jest/Vitest).
Getting AI to produce tests helps you verify whether its understanding matches yours.
When the Answer Is Vague
- Ask for "a line-by-line explanation, annotating what each key variable means."
- If context is lacking, paste in file snippets or interface definitions and have it revise the code.
- Have AI trace through step by step (input -> expected output -> actual output) to quickly spot where things diverge.
Practice
Take the "deduplicate and sort" function from the previous chapter, have AI write a test suite and explain the time complexity. Then ask it to evaluate whether there's a simpler implementation and explain the tradeoffs.
📚 Related resources
❓ Common questions
Open a question to review the practical answer.
Where should I actually start reading AI-generated code?
Read structure before details: (1) function signature — params, return type, fits project conventions; (2) dependencies — any new packages or wrong import paths; (3) boundary handling — how it treats empty input / null / exception branches. Pass those three before reading implementation. Diving into the body first lets local details hijack you, and you miss "the whole direction is wrong."
How do I get AI to check its own code?
Send a direct instruction: "List 3 scenarios where the code you just wrote could fail, and propose fixes. Also flag any performance risks or unhandled exceptions." AI's self-critique on its own output is better than people expect — typically catches 60-70% of obvious misses. Near-zero cost, far more effective than line-by-line eyeballing. Hand QA back to AI as a second pass.
Why is asking AI to write tests a good way to check our understanding aligns?
Because tests are the executable form of "how AI understood your requirement." Example: ask it to write 4 cases for the dedup function — empty input, duplicates, invalid input, happy path — using the project's existing Jest/Vitest setup. If AI's tests don't match your mental model, the prompt didn't convey the requirement clearly. That gap surfaces earlier than reading the implementation.
How do I push back when AI gives a vague or hand-wavy answer?
Three high-yield follow-ups: (1) "Explain line by line, annotate key variables" — forces AI to ground each line; (2) "Output an execution trace: input → expected → actual" — replaces abstraction with concrete data; (3) attach a file snippet or interface and ask for a revision — vagueness usually means missing context. Try in order. Beats asking "are you sure?" three times.
When AI says "this code works," should I trust it?
No. AI has no runtime, so "this works" is pattern-matched judgment, not verified output. Rule: every non-trivial change must actually run once — tests, lint, or a manual smoke through the critical path, at minimum one of three. The gap between "looks right" and "actually right" is wider in the AI era, because AI output rarely has syntax errors — bugs hide in edge cases and integration seams.