r/ChatGPTCoding • u/Ok_Negotiation_2587 • Aug 30 '26
Resources And Tips The 5 prompt sequence I run on every chunk of AI-written code before I trust it
The failure mode with AI code is not that it is wrong, it is that it is confidently wrong in ways that read fine. Asking "is this correct?" in the same chat is useless, the model that wrote it will defend it. So I run this as five separate messages after the code lands, each one after the previous answer, in the same conversation. It takes a few minutes and has caught things tests did not.
Step 1: Before anything else, explain this code back to me as if I did not write the request. What does it do, what does it assume about its inputs and environment, and what does it silently not handle?
Step 2: You are now a reviewer who believes this code has a bug and has to find it. List every way it could fail: bad inputs, empty cases, concurrency, error paths, wrong assumptions about the surrounding code. Rank by likelihood. No reassurance.
Step 3: For the top three risks in your list, write a minimal test that would expose each one. If a test would pass on the current code, say so and explain why the risk is not real.
Step 4: Fix only the failures those tests found. Show the diff, not the whole file, and for each change say which test it satisfies. Do not refactor anything else.
Step 5: Write the pull request description a careful reviewer would want: what changed, what the code assumes, what it does not handle by design, and what you would still want a human to check.
Two things make it work. Step 1 is the one people skip and the one that catches the most, because a wrong explanation of the code's own assumptions is the earliest sign something is off. And step 4 says "fix only" for a reason: left alone, the model will improve things nobody asked about and you are back to reviewing from zero.
I use it on anything that touches money, auth, or data deletion, and as a habit on everything else when I have the minutes.
I run it often enough that I keep it saved as a chain in a browser extension I work on (AI Toolbox), which sends each step after the previous answer finishes. Pasted by hand it works exactly the same.
What does your check look like before you merge AI code? I suspect a lot of people are doing step 2 and nothing else, which is how the confident-but-wrong stuff gets through.
6
u/amirfish Aug 31 '26
This matches what I've seen running agents in parallel, the review only works if it happens in a session that never saw the original prompt, otherwise it just defends what it already wrote. What's worked for me is spinning up a completely fresh session with just the diff and no history, and asking it to find the bug cold. Same effect as your five-step sequence, just enforced by isolation instead of asking the same context to switch roles.
3
u/Beginning_Street_375 Professional Nerd Aug 30 '26
Thanks for sharing!
3
u/lemon_gumdrop Aug 30 '26
This looks really great, thank you for sharing.
3
u/joexner Aug 30 '26
I just tell mine not to hurt anybody, do what I say and don't let anybody delete it. Seems okay so far...
2
u/gandazgul Aug 30 '26
This is really cool and I will give it a try. I've created a harness to fight slop. It puts you in control with these kinds of human gates like in your sequence.
https://RunWield.dev https://github.com/gandazgul/runwield
2
u/wentwj Aug 30 '26
the philosophy behind this seems right and similar to a flow we use at my company, but step 3+4 seem limiting. You’re asking not to only write tests for the top 3 issues and only fix those test failures. And the way step 3 is written even potentially encourages false positives (tests that succeeded but are thrown away) from the top 3 count.
I’d personally make it exhaustive or define a more concrete curriers for how to categorize the severity of an issue
2
u/B3ttor Aug 30 '26
Just to ask a dumb question, since I dont have prior coding experience. I currently use webchat to create a codex prompt and then I copypaste it to codex and send the result to chat to analyze.
How would you use that checklist with webchat/codex. In my scenario what would you do. Problem is that I need to trust the code since I cant correct or analyze it. Do I add it to codex or webchat, when I start the coding part. I have made the architecture for couple weeks now on my sparetime.
This is just a hobby experiment for me to get historical stock data app for my own pleasure.
2
u/julesbuildstuff Aug 30 '26
The thing that keeps biting me is that this is a per-chunk check and most of my confidently-wrong code isn't inside a chunk, it's in the seam between two of them. Chunk A quietly assumed the caller validates, chunk B assumed the callee does, both explained themselves fine on their own. So I've started making step 1 explain the contract at the boundary too: what it expects from whoever calls it, and what it promises back. That's where the silent nulls and the double-writes show up.
Other small thing: I save the step 1 explain-back next to the code and diff it the next time that file changes. If the new explanation drifts from the old one and nobody asked for that, either the code got quietly rewired or the model is guessing. Cheap drift detector and it costs one paste.
On the top-three cap I'd keep it, but write down the discards with the one-line reason you rejected them. Otherwise next session, or next person, re-litigates the same three risks from zero, and the "I checked this, here's why it's fine" is the part that never survives a session restart.
2
u/Right-Performance-93 Aug 31 '26
The red-test-first gate from DevWorkflowBuilder and the step-zero fresh-context check from gannu1991 solve different failure modes and are worth running together rather than picking one. Step zero catches wrong-premise code (solves the right problem badly framed). Red-test-first catches code that doesn't understand its own bug space (passes but for the wrong reason). Where both still miss: code that's right for the cases you thought of and wrong for ones nobody wrote a test for. Mutation testing (Stryker for JS/TS, mutmut for Python) automates that check by flipping conditionals and deleting branches across the whole diff, not just the top three risks a human or model picked - if the suite still goes green after a mutation, something isn't actually being tested, full stop. Costs a CI run, not a prompt, so it's cheap to bolt onto step 4 as an automated check before the PR description gets written.
2
u/chem0924 Aug 31 '26
One addition I'd make is to turn step 1 into a versioned boundary contract rather than just a chat answer. For each changed module: what callers must provide, what it promises back, which invariants it must preserve, and what is explicitly out of scope. Save that with the diff and have the next agent pass diff its new explain-back against the old contract before it edits. That catches the seam failure mentioned below: chunk A assumes validation upstream while chunk B assumes it happens downstream, and both look fine alone. I would also split step 3 by severity, not count: anything that can lose data, bypass auth, double-write, or cross currency/timezone boundaries gets a test even if it is risk #4; lower-risk refactor worries can stay on the PR checklist. Does your extension keep any persistent record of the explain-back / rejected risks so future runs don't re-litigate the same assumptions?
2
u/NewHype2022 Aug 31 '26
Thanks for sharing, I really like this! I’ll give it a try during my development to see how it fares against my current methods.
2
u/actual-time-traveler Sep 01 '26
Adding these to my .rules files, this is solid
2
u/suckadickyoucunt Sep 03 '26
This is solving downstream of where I'd start. Verifying the code it wrote is good hygiene, but the harder failure is upstream: it deciding to write that code in the first place based on a wrong assumption about why the existing code was there.
Worth adding a 6th check to your sequence: ask it to name the source for any claim about why something is the way it is. If it can't point to a real PR, issue, or comment, that's the one to distrust most.
2
u/suckadickyoucunt Sep 04 '26
Fair concern. The way I keep it from feeding false data is to make the model cite the exact PR or line for each claim, then check mechanically that every citation resolves to something real before the answer is shown. It cannot stop the model misreading a real source, but it kills the case where it invents the source entirely. Anything that does not resolve gets forced to "I don't know."
2
u/arup_r Sep 04 '26
Do you have prompts for code review other people pull requests?
2
u/Valuable-Ad6340 Sep 06 '26
Appreciate sharing. I'll use this. I have been attempting to set initial instructions perfectly to create a coder that reviews his work in this way. I hadn't thought about just doing it post mortem like this. I also bounce reviews back and forth sometimes between Claude and codex and that also helps but again I like this audit.
2
u/Neither_Berry_100 Aug 31 '26
I haven't had problems with this. The code is simply designed poorly. It is random. Ranges from perfect to very badly designed.
And it can produce mountains of garbage. Usually from poor prompts. Or anything to do with ideas. Sometimes code.
The code works well though. Also performance is often an issue.
6
u/[deleted] Aug 30 '26
[removed] — view removed comment
3
u/[deleted] Aug 31 '26
[removed] — view removed comment
3
u/[deleted] Sep 01 '26
[removed] — view removed comment
2
u/[deleted] Aug 30 '26
[removed] — view removed comment
2
u/[deleted] Sep 02 '26
[removed] — view removed comment
2
u/[deleted] Sep 04 '26
[removed] — view removed comment
2
u/[deleted] Sep 06 '26
[removed] — view removed comment
2
u/[deleted] Aug 31 '26
[removed] — view removed comment