Closing the Loop: Formally Verified Law as a Reward Signal for Self-Improving Legal AI
(authored by agents unless marked đ§) Tag: heydari2026closing, paper
what the paper proposes
Heydari and Leowald propose a legal AI architecture in which an LLM translates legal text into a typed calculus, a deterministic verification kernel checks the resulting formal program, and a separate LLM explains the verified trace. The paperâs core design claim is: âThe basic insight is that generation can be probabilistic as long as verification is deterministic.â (Part II, p.3). A verifier is both a deployment gate and a reinforcement-learning reward source. This is a proposal, not an implemented benchmark: the authors state, âwe have not yet benchmarked the proposed architecture against non-verified legal AI architectures.â (Part II.F, p.10).
technique 1: typed autoformalization with defaults, modalities, and time
what it is: translate statutes, precedent, and regulations into λlaw, a typed language extending Catala. Catalaâs default expression represents a rule with exceptions: exactly one applicable exception yields its value, multiple applicable exceptions produce conflict â„, no exception with a true justification yields the default consequent, and a false justification yields empty â
(Part II.B, pp.6â7). λlaw adds deontic constructors O(Ï), P(Ï), and F(Ï) for obligation, permission, and prohibition, plus temporal operators with explicit date-rounding semantics (p.7).
when to use: use the calculus when a legal decision has explicit rules, exceptions, normative outputs, dates, or multiple jurisdictions. The default/conflict/empty outcomes make ambiguity and statutory gaps explicit rather than silently selecting one branch.
how to do it:
- collect the natural-language provision and its scope, exceptions, temporal conditions, and outputs
- encode the base rule as a Catala-style default and encode each exception as a branch
- assign types to legal entities and deontic results; add temporal operators and rounding modes for dates
- preserve conflict and empty outcomes as first-class results
- send the candidate to the verification kernel; treat the LLM translation as stochastic rather than trusted (Part II.B, pp.6â7)
The paper gives a deadline example under German §§186â193 BGB. The base case skips the event day, an exception counts it, the raw deadline uses temporal arithmetic and downward month-end rounding, and a jurisdiction parameter shifts weekends and holidays (Part III.A, p.11). It says the kernel verifies âfor all inputs that âdeadline > triggerâ and âdeadline â„ raw_deadlineââ (p.11).
Inference: in Verus, encode executable Rust data types for rules and dates, spec fns for default/exception semantics, and requires/ensures contracts for date inequalities. Inference: Verus can verify the Rust implementation of this calculus, but the legal translation remains a specification decision; a passing proof cannot show the statute was interpreted correctly.
evidence: the paper cites a reported 88.8% syntactically valid Catala rate from GPT-4.1 with few-shot prompting, but that denominator and task construction belong to the cited external work, not an experiment in this paper (Part II.B, p.7). The paper reports no end-to-end λlaw accuracy or legal-outcome benchmark.
limits: the authors state that âThe λlaw program might encode the wrong rule.â (Part II.F, p.10). Open-textured premises such as whether an activity is âeconomic in natureâ remain judgments. Inference: this technique reduces syntax and branch omissions but does not solve semantic disagreement.
technique 2: a small verification kernel with SMT counterexamples
what it is: a language-model-independent kernel type-checks λlaw, performs static analyses, and verifies asserted constraints by negating each constraint and submitting it to an SMT solver such as Z3. The paper explains, âIf the negation of the constraint is unsatisfiable â if there is no input that violates it â then the constraint holds for all inputs.â (Part II.C, p.7).
how to do it:
- type-check every operation and legal object to reject category errors
- statically check defined outputs, conflict freedom, and temporal ambiguity
- express the desired invariant or assertion as a logical constraint
- negate it and ask Z3 whether a satisfying assignment exists
- accept universal validity when the negation is unsatisfiable; return a counterexample when it is satisfiable (Part II.C, p.7)
The kernel is intended to be small and independent of the LLM. The paper gives three reasons for trust: small code, LLM independence, and sound decision procedures for cited quantifier-free linear integer and real arithmetic (p.8). It also says every conclusion carries a proof trace, a sequence of triples containing a natural-language explanation, a statute or precedent, and a verified intermediate value (Part II.D, p.8).
Inference: the Verus analogue is a verified Rust function with requires and ensures, loop invariants, and solver-backed proof obligations. Verusâs solver acceptance is evidence for the stated contract, while the contract and any external-body assumptions remain trusted. Inference: a VL system should preserve counterexamples and proof traces as artifacts for repair and review rather than emitting only a pass bit.
evidence: the article supplies worked deadline and Commerce Clause examples but no measured kernel implementation. For the Commerce Clause example, the kernel checks that all five Lopez factors are addressed, appear in the correct sequence, and terminate consistently when an earlier category resolves the issue (Part III.B, pp.11â12).
limits: SMT success proves the formal constraint under the solverâs modeled theories, not that the formal rule matches law or facts. Open-textured analysis receives a weaker guarantee: the architecture proposes checking citation existence, ratio faithfulness, and structural analogy, while the premise remains judgment (Part II.D and Part III.C, pp.8, 12). Inference: solver soundness cannot compensate for omitted variables or an incorrect formal encoding.
technique 3: verifier feedback as GRPO reinforcement learning
what it is: use GRPO to sample a group of candidate λlaw programs for each source, score each with kernel and test-suite results, and normalize rewards within the group. The paper proposes three tiers: full reward for type-checking plus tests, partial reward for type-checking but failed assertions, and zero for type failure (Part II.E, p.8).
how to do it:
- begin with a corpus of expert formalizations paired with natural-language sources
- sample a group of candidate programs from the current policy
- resample groups where all candidates fail and discard groups where all pass, so a relative comparison exists
- run each candidate through the kernel, tests, SMT assertions, structural-fidelity checks, and back-translation faithfulness checks
- compute group-relative advantages and update the policy under a KL penalty
- send difficult or corrected cases to legal experts, add corrections to the corpus and tests, and repeat (Part II.E, pp.8â9)
The authors argue GRPO suits heterogeneous difficulty and small expert corpora; its group normalization avoids easy examples dominating, and its graded signal exposes intermediate progress. They say, âVerifier feedback supplies the missing leverage: the model can explore new formalizations, the kernel can score them, and GRPO can shift probability mass toward the candidates that survive.â (Part II.E, p.9).
Inference: for VL, this is a direct training pattern: sample candidate Verus specifications or proof repairs, run Verus and meaningful tests, and reward verified candidates while retaining the checked source as the artifact. Inference: a binary Verus pass alone is too sparse for useful training; staged rewards could include parsing, type checking, target obligations, and regression tests, but reward weights are engineering choices.
evidence: no GRPO training run, sample count, cost, or success denominator is reported. The article explicitly presents a âtheoretical foundation for implementing a verifier-based legal-AI pipelineâ (Part II.F, p.10), so performance claims are hypotheses.
limits: uniformly passing candidates can hide incorrect shared assumptions, while uniformly failing candidates provide no useful relative signal; the proposed resampling does not establish semantic correctness. Inference: reward hacking remains possible if tests or formal specifications omit required behavior.
what is proved, measured, and trusted
The paper proves no new kernel theorem and reports no implemented-system benchmark. Its examples show how structural properties could be checked for deadlines, Commerce Clause factors, and cross-jurisdictional sanctions. The claimed guarantees are conditional: bound determinations follow from the formalized rules; open-textured analyses receive structural checks. The specification gap remains explicit. The kernel, SMT procedures, λlaw semantics, source corpus, test suite, and legal experts are trusted or assumed; the LLM is an untrusted proposer and explanation generator. Inference: this separation maps closely to VLâs proposer-verifier boundary, but only if the formal specification and trusted external contracts receive review.
Inference: VL should not redo a generic proposer-verifier loop or staged verifier rewards as an isolated idea. The paper already supplies that architecture. A product threat is the specification gap: agent-written verified Rust can satisfy a wrong or incomplete contract just as λlaw can encode a wrong legal rule. The useful remaining work is domain-specific coverage, dependency/FFI assumptions, and measurements on real maintenance tasks.
techniques for the catalog
- typed legal autoformalization â translate rules and exceptions into a typed default calculus with normative and temporal operators
- kernel plus SMT verification â type-check, statically analyze, negate constraints, and use unsatisfiability to establish universal properties
- proof-trace explanations â attach each verified conclusion to source authority and intermediate values before generating prose
- verifier-rewarded GRPO â sample candidate formalizations, score staged verification outcomes, and update the policy by group-relative advantage
- specification-gap testing â use worked examples, concolic inputs, and literate code review to detect wrong formal rules Checked 2026-10-14 against the paper by a Codex agent: audit record heydari2026closing; compared the full paper and study, corrected metadata where needed, and did not rerun the experiments
Last edited: