Inspiration
LLMs are great at reading unstructured legal prose, but notoriously unreliable at arithmetic and formal logic. Ask a chatbot whether a residential security deposit plus a bundled refundable key fee violates California Civil Code § 1950.5, or on which exact day a daily late fee breaches a contractual cap, and it guesses.
For the Frankenstein category, we built a neuro-symbolic hybrid that stitches two opposite paradigms into one unexpectedly reliable tool: a probabilistic LLM for structured clause extraction, fused directly to Microsoft's deterministic Z3 SMT theorem prover for formal mathematical verification.
What It Does
ProofClause verifies residential leases and commercial contracts against statutory caps and internal mathematical constraints—with zero hallucinated math:
- Jurisdiction-Aware Formal Proofs: Supports India (Model Tenancy Act 2021), US / California (California Civil Code § 1950.5 & Automatic Renewal Law), and Internal Logic mode (pure mathematical constraints without country statutes).
- Presets, Raw Text & Unseen PDF Uploads: Extracts text from uploaded PDFs, parses clauses into strict Pydantic schemas (
R1Security Deposit,R2Late Fee Cap,R3Termination Notice,R4Auto-Renewal,R5Liability Cap,R6Uptime SLA), and passes them to Z3. Users can toggle between Highlighted Text and the Original PDF side by side. - Mathematical Counterexamples & Pinned Highlights: Returns deterministic
[SAT]/[UNSAT]verdicts with exact statute citations, inline red highlights on offending contract spans, and concrete counterexamples (deposit excess, notice gaps, late-fee overcharges, downtime overages). - Live Z3 What-If Sliders (<50ms): Numeric violations render interactive sliders (security deposit, days late, Party A / Party B notice periods) that re-solve server-side via Z3 in real time. Clauses flip from
VIOLATIONtoPASSin place while the source contract on the left stays pinned red as the ground-truth audit. - Durable Required Redlines: Tracks every before-and-after fix live as sliders move, remains visible even after all clauses flip
[SAT], and exports cleanly via[COPY REDLINES]or[EXPORT .MD]. - MCP Server Included: Exposes the exact same Z3 verification engine over the Model Context Protocol so external AI agents can invoke deterministic contract proofs directly.
How We Built It
- Backend: Python, FastAPI, Pydantic v2, PDF text extraction, and the Z3 SMT Solver (
z3-solver) translating extracted legal parameters into formal constraints and unsat cores. - Frontend: React, TypeScript, and Vite styled in an architectural brutalist paper-grid interface with a View Transitions API circular reveal dark-mode toggle.
- Agent Interface: Dedicated MCP server (
mcp_server/server.py) wrapping the same deterministic verification core. - Deployment: Fully containerized with Docker Compose and served behind Nginx at
https://proofclause.yshvrd.dev.
How We Used Kiro
ProofClause was engineered spec-first in Kiro, with the full .kiro/ directory tracked at the root of the repository:
- Kiro Specs (
.kiro/specs/proof-clause/): Defined formalrequirements.md, architecturaldesign.md, and structuredtasks.mdcovering all six clause constraint schemas, jurisdiction rule packs, API contracts (/api/analyze,/api/simulate), and UI state invariants before writing implementation code. - Kiro Steering (
.kiro/steering/): Enforced consistent separation between probabilistic extraction and deterministic Z3 proving, strict Pydantic schema validation, and brutalist UI design rules across backend and frontend iterations. - Iterative Verification: Used Kiro to drive implementation task-by-task alongside an automated
pytestsuite verifying Z3 boundary conditions, jurisdiction overrides, and edge cases.
Challenges We Ran Into
- Bridging Fuzzy Legal Prose to Strict SMT Constraints: Real leases hide fees across paragraphs (e.g., a
$4,200base deposit plus a separate$350refundable smart-key fee). Enforcing strict Pydantic extraction schemas ensured Z3 always received clean, typed numerical operands. - Keeping Audit Truth Separate from Live Simulation: Early builds turned the source contract highlights green when users dragged sliders, blurring what the actual signed document said versus what was simulated. Pinning left-panel highlights to the baseline
/api/analyzeverdict while keeping Required Redlines persistent across[UNSAT] → [SAT]flips solved this cleanly. - Sub-50ms Live Slider UX: Designing
/api/simulateto re-run only the lightweight Z3 solver (bypassing LLM extraction) made live slider dragging feel instantaneous even on custom uploaded PDFs.
Accomplishments That We're Proud Of
- Combining probabilistic LLM extraction with deterministic Z3 theorem proving into a fast, intuitive product that non-lawyers can actually use.
- Real-time server-side Z3 slider simulations working seamlessly on both presets and unseen uploaded PDFs.
- Shipping a live, Dockerized production deployment alongside an MCP server and full automated test coverage.
What We Learned
LLMs should be treated as translators into formal models, not as the judges of mathematical or statutory compliance. Pairing Kiro's spec-driven workflow with formal verification constraints eliminates entire classes of hallucination bugs by construction.
What's Next for ProofClause
- Expanding jurisdiction rule packs (additional US states, EU consumer directives, and commercial SaaS MSA templates).
- Direct DOCX redline export with native Track Changes annotations.
- Deeper Kiro / MCP agent workflows that automatically draft compliant counter-clauses verified by Z3 before sending.
Testing Instructions for Judges (No Login Required)
- Open https://proofclause.yshvrd.dev (no account or login required).
- Click Start → choose India (or US/CA) → select any built-in preset (or upload your own lease PDF / paste contract text) → click Run Proof.
- Inspect the
[UNSAT]verdict, inline red highlights on the left document, KPI counterexamples, and proof cards on the right. - Drag the Z3 what-if sliders (e.g., lower Security Deposit to the statutory cap or match Party A / Party B notice days) to watch clauses re-solve in milliseconds and flip to
PASS/[SAT], while the original text stays pinned red and Required Redlines logs every before-and-after diff for.mdexport.
- Want to test PDF upload? Download the synthetic test leases (including the San Francisco lease from the demo video) here:
https://github.com/yshvrd/ProofClause/tree/main/sample-pdfs
Built With
- amazon-web-services
- docker
- fastapi
- kiro
- mcp
- nginx
- pydantic
- pytest
- python
- react
- typescript
- vite
- z3