VeriTool
Runtime trace invariant verification for multi-agent LLM systems. Z3 + Lean 4.
v = Verifier()
v.register_tool("deploy", action_type="DEPLOY", resource_fn=lambda a: a.get("env"))
v.register_tool("build", action_type="BUILD")
v.register_tool("test", action_type="TEST")
v.add_invariant(OrderingInvariant("DEPLOY", ["BUILD", "TEST"]))
deploy = v.wrap(my_deploy_fn)
build = v.wrap(my_build_fn)
test = v.wrap(my_test_fn)
Every tool call is checked against accumulated action traces before execution. Violations are blocked with counterexamples.
Architecture
Tool Call → Verifier.wrap() → Z3 encodes all 4 invariants as SMT constraints → UNSAT (permit) / SAT (block + counterexample)
↑
Lean proves:
Z3 encoding ⊧ invariant semantics
Four invariant types, all encoded as Z3 satisfiability queries:
| Invariant | Checks |
|---|---|
OrderingInvariant("DEPLOY", ["BUILD", "TEST"]) |
Before any DEPLOY, BUILD and TEST must have completed |
ExclusiveAccessInvariant("WRITE") |
No two agents concurrently WRITE to the same resource |
ApprovalInvariant("DEPLOY", "APPROVE") |
DEPLOY requires prior APPROVE by a different agent |
MonotonicInvariant("SPEND", resource_key="value") |
Values can only increase (per-agent, per-resource) |
Each check creates a z3.Solver, encodes the violation condition as a SAT query, and returns a counterexample model on violation. This uniform SMT pipeline enables formal soundness proofs in Lean.
Why Z3 + Lean?
Existing policy engines (OPA/Rego, AWS Cedar) check single actions against static rules. They cannot enforce invariants that span multiple agents across sequences of actions — e.g., "no deploy without prior build and test."
Z3 encodes the accumulated action trace and invariants as SMT constraints. Lean proves the encoding is sound — each invariant is defined as a Lean Prop with nil/snoc structural induction theorems showing that a Z3 permit preserves the invariant.
Related work: Lean4Agent (UIUC, June 2026) uses Lean 4 for design-time workflow verification. VeriTool targets runtime interception with Z3 for fast SMT checking and Lean for proof of encoding correctness.
Usage
from verifier.verifier import Verifier
from bridge.invariant import OrderingInvariant, ExclusiveAccessInvariant
v = Verifier(agent_name="ci-bot")
v.register_tool("deploy", action_type="DEPLOY", resource_fn=lambda a: a.get("env"))
v.register_tool("build", action_type="BUILD")
v.register_tool("test", action_type="TEST")
v.add_invariant(OrderingInvariant("DEPLOY", ["BUILD", "TEST"]))
v.add_invariant(ExclusiveAccessInvariant("DEPLOY"))
deploy = v.wrap(deploy_to_production)
build = v.wrap(run_build)
test = v.wrap(run_tests)
assert build() == ...
assert test() == ...
assert deploy(env="prod") == ... # only permitted if BUILD + TEST completed
v.reset() # clear trace for a new session
Project Structure
bridge/ # Action trace model + invariant types + Z3 encoding
verifier/ # Generic Verifier with wrap()
Lean/Trace.lean # Soundness proofs for invariant encoding (3 invariants proved)
policy_store/ # Versioned policy store + audit trail
tests/ # pytest suite
benchmark/ # Scalability, throughput, 3-way OPA comparison
Tests
make test # 14 tests, all pass
make verify # Lean theorem compilation check
Benchmark Results
Full results in BENCHMARK_RESULTS.md.
Detection Rate
| System | Correct | Rate |
|---|---|---|
| OPA (stateless) | 14/24 | 58% |
| OPA+history | 24/24 | 100% |
| VeriTool | 24/24 | 100% |
Latency & Throughput
| System | μs/action | Actions/sec |
|---|---|---|
| VeriTool | 175 | 5,703 |
| OPA stateless | 10,262 | 97 |
| OPA+history | 11,188 | 89 |
VeriTool is ~60x faster than OPA across both stateless and history modes.
Scalability
All invariants remain sub-millisecond up to 1000-trace entries. Per-check latency grows near-constantly (2-3x from size 1 to 1000).
Formal Soundness
Three of four invariant types are proved correct in Lean via structural induction:
ordering_invariant— nil/snoc theoremsexclusive_access_invariant— nil/snoc theoremsapproval_invariant— nil/snoc theorems
Each theorem's hcase (safety condition) corresponds exactly to the Z3 encoder's violation check.
Reproduce
make all # Lean verify → tests → benchmark → 3-way OPA comparison
Requires OPA installed:
curl -sL -o /usr/local/bin/opa https://github.com/open-policy-agent/opa/releases/download/v1.2.0/opa_linux_amd64_static
chmod +x /usr/local/bin/opa
Docker
docker build -t veritool .
docker run --rm veritool make all
The Dockerfile pins Python 3.13, Lean 4.15.0, OPA 1.2.0.
License
Apache 2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file veritool-1.2.0.tar.gz.
File metadata
- Download URL: veritool-1.2.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bb7f2302a8126a04b11969ce9a161e0560bdb600e3990f5b2e1b1d438684990
|
|
| MD5 |
178ffef5d96cad21fac8513182e4a8e9
|
|
| BLAKE2b-256 |
035191d619aefcf678fe005df40bdeed958b5ce3501c0bdfdff42423752165ec
|
Provenance
The following attestation bundles were made for veritool-1.2.0.tar.gz:
Publisher:
publish.yml on Pranav-d33/veritool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
veritool-1.2.0.tar.gz -
Subject digest:
6bb7f2302a8126a04b11969ce9a161e0560bdb600e3990f5b2e1b1d438684990 - Sigstore transparency entry: 2084865053
- Sigstore integration time:
-
Permalink:
Pranav-d33/veritool@824d4b757d5e8d71b9a9786582de9ad6327b55a9 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Pranav-d33
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@824d4b757d5e8d71b9a9786582de9ad6327b55a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file veritool-1.2.0-py3-none-any.whl.
File metadata
- Download URL: veritool-1.2.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84a1df4b4bc1fc1aeee27d37724295faf939c4ceb6225d379df58778859d2607
|
|
| MD5 |
548841f0c600a14d81d6784dcf1d1c76
|
|
| BLAKE2b-256 |
61143ac321edb4b465fe4c8f4aeeca8063bc217aea3694cabb12bf43636c4a71
|
Provenance
The following attestation bundles were made for veritool-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on Pranav-d33/veritool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
veritool-1.2.0-py3-none-any.whl -
Subject digest:
84a1df4b4bc1fc1aeee27d37724295faf939c4ceb6225d379df58778859d2607 - Sigstore transparency entry: 2084865099
- Sigstore integration time:
-
Permalink:
Pranav-d33/veritool@824d4b757d5e8d71b9a9786582de9ad6327b55a9 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Pranav-d33
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@824d4b757d5e8d71b9a9786582de9ad6327b55a9 -
Trigger Event:
push
-
Statement type: