Invariant: Property-Based Testing for LLMs, Seven Invariants, Automatic Shrinking

LLM quality often looks good on fixed examples and then breaks on slight rephrasing. Invariant tackles that by testing behavioral properties rather than exact output strings.
You define what should stay true (for example consistency, instruction following, language matching), and the framework generates adversarial variants to find violations.
Why It Matters
Property-based checks catch fragile prompt behavior before users do. Automatic shrinking then reduces failures to minimal reproductions so fixes are faster and less subjective.
This turns fuzzy model QA into something that fits engineering workflows and CI.
Run the Project
pip install invariant-llm
invariant run --model gemma4:e4b --backend ollama --invariants consistency 'Explain quantum entanglement'
invariant list-invariants
pytest tests/ -v -m llm_invariant
The pytest marker in the README is llm_invariant; this keeps test instructions aligned with repository docs and easy to run in existing test suites.
Architecture Walkthrough
The invariant property testing llms repository is organized around a clear pipeline, so you can trace the full flow from input handling to final output without guesswork. This makes onboarding easier for new contributors and helps teams debug faster when behavior changes after updates.
Practical Use Cases
If you are evaluating invariant property testing llms for production, start with a small real-world dataset, run the included commands end to end, and compare output quality, latency, and operational complexity. This gives a practical signal that is stronger than a toy demo.
Implementation Notes
The project is useful as both a standalone tool and a reference implementation. You can copy patterns from this codebase into your own stack, especially around evaluation discipline, reproducibility, and operator visibility.
Try NEO in Your IDE
Install the NEO extension to bring AI-powered development directly into your workflow:
- VS Code: NEO in VS Code
- Cursor: Install NEO for Cursor