Guides · Building with AI
Guides · Building with AI
Trust the code an AI wrote the way you would trust work from a contractor you have never met: on what you can check, not on how confident it sounds. Keep it when it is small enough to read, you can explain what every part does, a test fails without it, and it lives somewhere a mistake cannot leak data or money. Throw it out when you are on your third fix for the same bug, when it has quietly grown past what you asked for, or when it touches sign-in, payments or other people's data and you cannot verify it line by line. The decision is never about the AI. It is about whether you can stand behind the code.
This is the judgement chapter of our guide to building an app with AI in 2026. The previous chapter, how to review the code an AI wrote, gave you the five checks to run on every change. This one is about what to do with the result: when a change that passed review is still not worth keeping, and when the right move is to delete it and start again, smaller.
Developers have already made this call in the aggregate, and they made it the right way round. In Stack Overflow's 2025 Developer Survey, 84% of developers use or plan to use AI tools, yet 46% distrust the accuracy of what those tools produce and only 3% trust it highly. Google's 2025 DORA report, built on nearly 5,000 responses, finds the same shape: adoption near 90%, high trust at 3%. That is not a contradiction. It is professionals using a fast tool whose output they verify, the way a good accountant uses a calculator and still checks the total.
So the question is never whether to trust the AI. It is whether you can trust this particular change, and that depends on things you can check: how big it is, whether you can read it, whether a test proves it, and what it touches. Trust that comes from the AI sounding sure is worth nothing. The code reads cleanly whether it is right or wrong.
Run every AI-written change through five questions. Each has an answer that says keep, and an answer that says delete it and regenerate smaller. Anything in between is a fix, and fixes are counted, as the last row explains.
| Question | Keep it when | Throw it out when |
|---|---|---|
| Can you explain it? | You can say what each function does and why it is there | You would be guessing, or you are keeping it because it "seems to work" |
| Does a test prove it? | A test fails when you remove the change and passes with it | There is no test, or the test the AI wrote only asserts that the code ran |
| Did it stay inside the ask? | The diff touches the files you expected, at roughly the size you expected | It rewrote things you did not ask about, added a second copy of logic you already had, or changed a shared file |
| What does it touch? | UI, formatting, glue code, a feature you can switch off | Sign-in, permissions, payments or other people's data, and you cannot verify every line |
| How many fixes so far? | First or second pass, each fix smaller than the last | Third fix for the same bug, or each fix breaks something else |
AI code is at its best in the parts of an app that are boring, well known and easy to check: a form and its validation, a page layout, a database query you can run by hand, a converter between two formats, the scaffolding for a test suite. There are thousands of correct examples of each in the model's training data, the result is easy to eyeball, and a mistake shows up on screen rather than in someone else's account.
Keep it when four things are true at once. It is small enough to read in a few minutes. You can explain what every part does. Something fails if the code is wrong: a test, a type check, or a visible error. And it lives where a bug costs you an afternoon, not a customer. Under those conditions AI code is not a risk to manage. It is a draft you have already checked, and it is often better structured than what you would have typed in a hurry.
The one habit that keeps this honest is reading the diff before the demo. The temptation after a generation is to click the button and see if it works. Read first, then run. A thing that works for the one input you tried and that you have not read is not trusted code. It is untested code with a good first impression.
The first signal is the fix loop. You ask for a change, something breaks, you paste the error, the AI patches it, something else breaks. Each patch is plausible on its own, and together they turn a simple function into a pile of special cases. Our rule is three: the third time you are fixing the same thing, stop patching. Delete the change, improve the prompt with what you learned, and regenerate it smaller, or write that piece by hand.
The second is duplication. Models reach for a fresh copy of logic rather than reusing the one you already have, because a copy is the shortest path to a passing result. GitClear's analysis of 211 million changed lines found that 2024 was the first year on record in which copy-pasted code inside a commit exceeded code that was moved or refactored. Two copies of the same rule is a bug waiting for the day you fix one of them. If an AI change duplicates something that exists, throw out the copy and point it at the original.
The third is the sensitive zone. If the change touches sign-in, who can see what, money, or another user's data, trust is not available as a shortcut. Either you verify it line by line, with the five checks from the review chapter, or it does not ship. Broken access control is the number one risk in the OWASP Top 10 for 2025, and it is where AI code fails most often, in exactly the way the security holes guide describes. Here the rule is simple: if you cannot verify it, you cannot keep it.
The fourth is the time check, and it is the one people miss. In a 2025 randomized study by METR, experienced developers working in codebases they knew well took 19% longer to finish tasks with AI tools than without, while believing they had been about 20% faster. The gap comes from reading, fixing and re-prompting output that was almost right. So when you notice that understanding and repairing a generated change is taking longer than writing it would, that is not a feeling to push through. It is the signal that this particular change should go.
Deleting AI code feels expensive because you watched it appear. It is not. What took the time was the thinking: what the feature has to do, what the data looks like, what has to be true for it to be right. All of that survives. Keep the spec, keep the tests, keep the database schema, and delete the implementation.
Then regenerate with constraints you did not have the first time. Ask for one function, not a feature. Name the file it may touch. Tell it which existing helper to reuse. Paste the test it has to pass. A second attempt scoped like this usually comes back smaller and readable, and if it does not, you have learned that this piece is one to write by hand. That is a cheap lesson compared to maintaining code nobody understands.
The sunk cost is the trap. The cost of AI code is not the minute it took to generate. It is every future hour someone spends reading it, debugging it and working around it. The same DORA report found that teams adopting AI shipped more and faster, and also saw more instability: more failed changes and more rework. That rework is the bill for code that was kept because it was already there. Throwing out a change on the day it was written is the cheapest moment you will ever have to do it.
Keep AI code you can read, explain and prove, in a place where a mistake is cheap. Throw out code you are patching for the third time, code that duplicates what you have, code in the sensitive zone you cannot verify, and code that is costing more to understand than to write.
We build with AI every day and we keep most of what it writes, because we keep it to the places where it earns trust: layouts, forms, glue, tests. Anything that touches sign-in, permissions, payments or client data is read line by line and is rewritten more often than it is kept, and nothing ships until it has passed a review that assumes it is wrong. That is the same discipline we charge for in our process, and it is why the pricing for a build includes the review, not just the generation.
Our open tools exist because of this rule. Grillin' checks the plan before any code exists, since most AI code that gets thrown out was asked for badly. Smokin' takes an agent that reports "done" and re-runs the check instead of taking its word. Both are on the projects page.
If you have an AI-built app and you are not sure which parts to trust, book a production-readiness check: we read the code and tell you plainly what to keep, what to fix and what to replace. We have shipped 15 apps this way, with 2 more in progress, each one pen-tested before it went live, and a small one is usually ready in two to four weeks.