AI coding prompts for explanations, debugging, and review
Coding prompts work best when they describe an observable problem and provide the relevant code. A language name and a request to “improve this” rarely explain the behavior the project needs to preserve.
Provide a small, relevant slice of context
Include the function or module, its callers when needed, and the language or framework version used by the project. For a bug, provide the input, expected result, actual result, and exact error message. Remove credentials and private data from logs and examples.
Ask for evidence before a broad rewrite
For a review, request concrete defects with the affected code, a triggering input, and an explanation of the consequence. For debugging, ask the assistant to separate observations from hypotheses and identify missing information. This makes the proposed fix easier to assess.
State the boundaries of the change
Mention compatibility requirements, public APIs, dependency constraints, and behavior that callers rely on. If you need a minimal patch, say so. If performance is the concern, supply measurements or describe the workload rather than assuming shorter code will be faster.
Use your project’s review process
Inspect the diff, consider edge cases, and run the checks appropriate to your project. An assistant’s explanation is not evidence that the code executes correctly. Save the review rubric in a reusable prompt when your team repeatedly checks the same kinds of changes.
A prompt to adapt
Review this [language] function for correctness. Expected behavior: [contract]. Environment: [versions and relevant dependencies]. Identify concrete issues, explain an input that triggers each one, and suggest the smallest fix. Distinguish confirmed defects from questions that require more context. Code: [code]
A worked example
This written example illustrates the requested result. Your assistant’s answer will vary.
Expected behavior: archived documents cannot be edited, including by owners and admins. Review this JavaScript expression: return user.id === doc.ownerId || user.role === "admin" && !doc.archived;
An owner passes the first side of the OR expression, so the archived check applies only to admins who are not owners. Put the archived condition around both permission checks: return !doc.archived && (user.id === doc.ownerId || user.role === "admin");
What to look for
The review identifies a specific mismatch with the supplied contract and gives a narrow change. It should still flag any missing context, such as whether user or doc can be null, rather than claim the whole permission system is correct.
Templates for this workflow
Code review feedback
You are reviewing a pull request. Review the supplied code for correctness, readability, maintainability, edge cases, and security concerns. Use the context below for the code, pro