Name the file, the behaviour and the constraint. Then ask for the test.
Code prompts fail differently from prose prompts. A vague writing prompt gives you a bland paragraph; a vague code prompt gives you a plausible function with the wrong signature that silently breaks a caller. The fix is the same discipline as everywhere else, tightened: name the context, state the behaviour, bound the change, and ask for evidence.
Give the model the code it must respect
A model cannot follow conventions it cannot see. Paste the relevant file, or at least the interface it must satisfy and one example of the project's style. Say which framework and version, because the difference between two major versions is often the whole answer. "Use the existing helper" is meaningless without the helper in the prompt.
Describe the function in terms of what goes in and what comes out, including the edge cases: empty list, null, duplicate keys, very large input. Behaviour is testable; intent is not. "Make it robust" invites defensive code that swallows errors. "Return an empty array when the input is empty; throw InvalidArgumentException when the id is not an integer" is a specification you can verify.
Bound the blast radius
Say what must not change: public methods, database schema, response shape, existing tests. A model asked to fix a bug will happily refactor three files, and every extra file is a new risk in review. Narrow scope produces a reviewable diff, and a reviewable diff is the only kind that gets merged with confidence.
Example: "In app/Services/PriceService.php, add a method totalPaisa(array $lines): int. Sum price_paisa times quantity using integer arithmetic; throw InvalidArgumentException on a negative quantity. Do not change existing methods. Add one test covering an empty array and one covering a negative quantity."
Ask for the test with the code
Requesting a test does two things: it forces the model to state the expected behaviour, and it gives you something to run. Run it. A test that passes proves less than you think, but a test that fails tells you exactly where the prompt and the code disagreed. For anything touching money, dates or permissions, the test is not optional.
Review like a stranger wrote it
Read the diff as if a new colleague submitted it. Are the names clear, is the error handling honest, is there a query per row, is a secret logged? Models reproduce the patterns in their context, including bad ones. The reviewer's job is unchanged by the fact that a model typed the code; if anything, the review matters more because the code arrives fluent and unowned.
Checklist
- Is the relevant code and version in the prompt?
- Is behaviour stated as input, output and edge cases?
- Is the allowed scope explicit?
- Does the change ship with a runnable test?