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.
Research-validated principles for AI code generation
Pure logic (Core) and I/O (Shell) must be physically separate
Define COMPLETE boundaries that uniquely determine implementation
Read map → signatures → implementation (only if needed)
Break complex tasks into sub-functions before implementing
If fail: Reflect (why?) → Fix → Verify again
Verify all feature paths connect; local correctness ≠ global correctness
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 — Smart Guard runs static + doctests |
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.
Choose depth based on your needs
pip install python-invar
invar init
AI follows INVAR.md