AI Prompts for Coding: Reviews, Refactors, Tests and Debugging
AI is most useful in coding when the task has a verifiable answer: does the test pass, does the type check, does the bug reproduce. Prompts that lean on verification produce far better results than prompts that ask for opinions.
Code review
Ask for specific classes of problem rather than "review this". Naming the categories — race conditions, unhandled errors, N+1 queries, off-by-one — produces concrete findings instead of style commentary.
Refactoring
State the invariant that must hold: "refactor this to remove the nested callbacks; behaviour and public API must not change". Without a stated invariant the model will happily improve the code and break it.
Test generation
Ask for the edge cases first, then the tests. "List the edge cases for this function, then write a test for each" reliably beats "write tests", which tends to produce three happy-path cases.
Debugging
Give the model the error, the relevant code, and what you already ruled out. The last part matters most — without it you get the same three obvious suggestions every time.
Explaining unfamiliar code
Ask for the data flow rather than a line-by-line description: "trace what happens to the request object from entry to response". Line-by-line explanations restate the code; data flow explains it.
The rule that matters
Never ship generated code you have not read. The failure mode is not code that crashes — it is code that looks right, runs, and is subtly wrong.