Code Review
Get a prioritized code review that covers correctness, security, readability and tests.
Diagnose an error by giving the AI the message, the code, what you tried and what you expected.
Help me debug an error. Think like a careful engineer: find the cause before proposing a fix.
<environment>
{environment}
</environment>
<error>
{error_message}
</error>
<code>
{code}
</code>
<behavior>
Expected: {expected_behavior}
Actual: {actual_behavior}
Already tried: {already_tried}
</behavior>
Answer in this order:
1. What the error message means, in plain words.
2. The most likely cause, pointing to the exact line or condition. Give your confidence (high, medium, low).
3. Two other possible causes, and a quick check that would rule each in or out.
4. The fix: a corrected code snippet, and a sentence on why it works.
5. How to confirm it is fixed: the exact steps or test to run.
6. How to prevent the same kind of error in future.
If the information is not enough to find the cause, do not guess. Tell me what extra information you need, such as logs, a variable value or the calling code, and how to get it. Do not suggest changes unrelated to the error.| Variable | What to put in | Example |
|---|---|---|
| {environment} | Language, framework, versions and operating system. | Python 3.12, FastAPI, macOS. |
| {error_message} | The full error message and stack trace. | Paste the exact text from your terminal. |
| {code} | The code related to the error. | Paste the relevant function and the line where it fails. |
| {expected_behavior} | What should happen. | The endpoint should return a list of users. |
| {actual_behavior} | What happens instead. | It returns a server error when the list is empty. |
| {already_tried} | What you already tried. Write "nothing yet" if nothing. | Restarted the server; checked that the database is running. |
Meaning: the code reads the first item of a list that is empty, which raises an IndexError. Likely cause (high confidence): get_users() returns [] when there are no users, and line 14 reads users[0] without checking. Fix: return an empty list when users is empty. Confirm: call the endpoint with an empty table and check that it returns [] with a 200 status.
Claude tends to follow the cause-first order well. Keep the instruction not to guess so it asks for missing logs instead.
Works as-is. If the bug is spread across files, paste the call path rather than one function.
If you can attach log files or a code export, name them and point to the lines that matter.
Include exact versions. Ask it to say when a fix depends on the library version, and confirm against the library's documentation.
Explain the cause as if I were new to this language.Add a regression test that would have caught this error.Show a second, more defensive version of the fix.Get a prioritized code review that covers correctness, security, readability and tests.
Generate unit tests that cover normal cases, edge cases and failures, with the reasoning for each.
Improve the structure and naming of code without changing what it does, with a list of changes.