| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
IntentGuard lets you test code intent with natural language assertions.
Use it when a property is real and test-worthy, but awkward to encode with ordinary assertions: architecture rules, security practices, documentation contracts, error-handling conventions, or other cross-cutting code qualities. IntentGuard checks referenced code with a local model and raises AssertionError when the judgement fails.
IntentGuard complements traditional tests. Keep unit tests for exact outputs, edge cases, state changes, and safety-critical behavior. Use IntentGuard where a custom AST walk, linter rule, or review checklist would be noisy or expensive.
Important
The current default model is IntentGuard-1-qwen2.5-coder-1.5b, with 92.5% accuracy and 92.3% precision in the validation suite.
pip install intentguardimport intentguard as ig
def test_code_properties():
ig.assert_code(
"Classes in {module} should follow the Single Responsibility Principle",
{"module": my_module}
)
ig.assert_code(
"All database queries in {module} should be parameterized to prevent SQL injection",
{"module": db_module}
)import unittest
import intentguard as ig
class TestCodeQuality(unittest.TestCase):
def test_error_handling(self):
ig.assert_code(
"All API endpoints in {module} should have proper input validation",
{"module": api_module}
)IntentGuard works best for high-level properties that are easy to describe and hard to check directly:
Avoid using it for exact numeric results, runtime behavior that must be executed, or anything that needs perfect determinism. Model judgement is useful signal, not proof.
IntentGuard is designed for repeatable judgements, not guaranteed determinism. It uses low-temperature sampling, repeated evaluation, strict majority voting, and caching to make results stable in normal test runs. Fresh model evaluations can still vary, especially after changing the assertion, code, model, temperature, or evaluation count.
Configure repeatability:
import intentguard as ig
ig.set_default_options(
ig.IntentGuardOptions(
num_evaluations=7, # More evaluations make majority vote more stable
temperature=0.1, # Lower temperature reduces sampling variance
)
)Use module-level ig.assert_code(...) for ordinary tests. Use ig.IntentGuard(options) when one test class, suite, or subsystem needs isolated options.
IntentGuard uses a custom 1.5B parameter model, fine-tuned from Qwen2.5-Coder-1.5B for code property verification. It runs locally through llamafile, so code is not sent to a hosted API by default.
| Model | Accuracy | Precision | Recall |
|---|---|---|---|
| (current model) IntentGuard-1-qwen2.5-coder-1.5b | 92.5% | 92.3% | 89.4% |
| (previous model) IntentGuard-1-llama3.2-1b | 92.4% | 91.0% | 91.0% |
| (reference model) gpt-4o-mini | 89.3% | 85.3% | 90.2% |
The validation suite is intentionally strict:
For more details, see the validation documentation.
IntentGuard requires Python 3.10+. OS and architecture support come from llamafile:
Useful commands:
| Back | FazBrowse Home | New Git URL |