You use AI to write code. How do you know it's correct?
Invar makes AI prove its code is correct through contracts, verification, and mechanical checks.
These laws shape how AI writes and organizes code
Pure logic (Core) and I/O (Shell) must be physically separate
Define boundaries (@pre/@post) before implementation
Read map → signatures → implementation (only if needed)
Run invar guard && pytest after every change
AI follows this workflow for every task
| Intent | Core function (pure logic, no I/O) |
| Contract | @pre: price > 0, discount ∈ [0,1]. @post: result ≥ 0 |
| Inspect | invar sig — check existing patterns |
| Design | File size OK, no extraction needed |
| Implement | Write code with contracts and doctest |
| Verify | invar guard && pytest — all pass |
Contracts are written by AI, not by you. You don't review every one.
Without constraints, AI writes code that "looks right." With constraints, AI must think through boundaries before writing — this thinking process itself reduces bugs.
AI can't ignore edge cases because Guard catches them. Violations are fixed before you even notice.
Three commands to get started
pip install python-invar
invar init
AI follows INVAR.md