LearnGrok
Prompts
PromptIntermediatePrompting

Code review and debugging prompts

Prompts for getting a real review instead of praise, narrowing a bug you cannot reproduce, and understanding code you did not write.

2 min read

The theme: assistants default to being agreeable, and an agreeable code review is worthless. Each prompt here either narrows the job to something falsifiable or explicitly forbids padding.

Use these with real code: not simplified code

Trimming the code before you paste it removes exactly the context that makes a review useful, the surrounding calls, the error handling, the types. Paste the real thing, and remove secrets rather than complexity.

About the fix

Notice that the debugging prompt asks for causes and checks, not a patch. A patch against an unconfirmed diagnosis is how you end up with two bugs. Get the check first, run it, then ask for the fix with the confirmed cause in hand.

What changes

Nothing here is model-specific. If your model's review comes back consistently shallow, add the constraint "assume there is at least one real bug and find it", and then discard the answer if it turns out there wasn't one. Prompted suspicion is a useful lens, not evidence.

Copy-ready prompts

4 prompts. Open one to read it, or take the whole pack.

1Review for correctness onlyYou want bugs found, not style opinions.
Review the code below for correctness only. Ignore style, naming and
formatting entirely.

For each finding, give:
- The exact line or function
- The concrete input or state that triggers it
- What goes wrong as a result

Rank by severity. If you find nothing that meets that bar, say "no
correctness issues found" and stop; do not pad the list with
suggestions.

Code:
"""
<paste here>
"""
2Narrow a bug you cannot reproduceYou have a symptom and no idea where it comes from.
Symptom: <what you observe>
Expected: <what should happen>
Environment: <runtime, versions, platform>
What I have already ruled out: <list>

Relevant code and logs:
"""
<paste here>
"""

Give me the five most likely causes, ordered by probability. For each:
- Why it would produce exactly this symptom
- The cheapest single check that would confirm or eliminate it

Do not propose a fix yet. I want to know what to check first.
3Explain unfamiliar codeYou have to change code you did not write.
Explain the code below to someone who has to modify it safely.

Cover, in this order:
1. What it does, in two sentences.
2. The inputs it assumes and the invariants it relies on.
3. What breaks if each of those assumptions is violated.
4. The parts most likely to have subtle bugs, and why.

Do not describe it line by line. Do not suggest improvements.

Code:
"""
<paste here>
"""
4Test cases from a specificationYou want the cases you did not think of.
Here is the intended behaviour of a function:
"""
<describe the contract>
"""

List test cases as a table: | Input | Expected | Why this case matters |

Include: the ordinary case, boundaries, empty and maximal inputs, invalid
types, and any case where two requirements above interact. Mark any case
where the specification above does not actually determine the answer, those are specification bugs and I want them separated out.

Last checked against xAI’s own pages on 2026-08-20. Grok changes quickly; anything version-specific should be confirmed upstream before you rely on it.

More in Prompting

Found something out of date?

Grok changes quickly and this page is a snapshot. If something here is wrong, or you know a better resource, send it over.

Suggest a link →

Advertise on LearnGrok

$420.69one-time, for a 30-day run

Square works best. PNG, JPEG or WebP, up to 2 MB.

Stripe on the next step. Live once approved.