Code that validates itself: AI-generated assertions
Only about 2.5% of open-source Java repositories use production assertions. LLMs can write them, adding the verification layer AI-written code needs.
Production assertions are one of the cheapest verification tools we have, and almost nobody writes them. The Assertify paper reports that only about 2.48% of the open-source Java repositories the authors examined contained production assertions. The reason is simple: writing good assertions by hand takes effort and domain knowledge, and there is always something more urgent.
The paper shows that LLMs can generate meaningful assertions comparable to those written by experienced developers. That caught my attention because assertions do three useful things at once. They validate assumptions at runtime, they make debugging faster by failing close to the cause, and they document intent right next to the code.
I think this matters more now than when the paper was written. As more code is generated by AI, we need verification that lives inside the code, not only in a separate test suite that may itself be generated. An assertion that states what must be true at a given point is a small, readable contract that both humans and agents can check.
If AI is going to write more of our code, it should also write down what that code assumes.
Cite this: Bommiah, M. (2025, May 13). Code that validates itself: AI-generated assertions. muthub.org. https://muthub.org/writing/ai-generated-assertions
Adapted from my LinkedIn post of May 11, 2025, on the Assertify paper. Views are my own and do not represent my employer.
