Research15th July 2026

Turning rulebooks into verified tools

All posts

We had AI agents read three real rulebooks, the NBA Collective Bargaining Agreement, the IRS Form 1040 instructions, and an airline baggage policy, and turn each into an executable Lean function with machine-checked properties. At run time an LLM only extracts the facts of a case, and the verified function applies the rules. On RuleArena, the benchmark built from these rulebooks, the tools score 90.7–100%, and every verdict traces to the rules that produced it. Along the way, the tools ended up auditing the benchmark itself.

Build once: a rulebook (a rule in prose) becomes a Lean function, the rule as executable code, and a prover proves its stated properties hold for every formal input, giving a verified, executable Lean tool. Run, each query: an LLM turns the case into structured inputs, the verified function is called, applies the rules, and returns an exact, traceable answer.
Each rulebook (NBA transactions, US income tax, airline baggage fees) becomes a proved, executable Lean function. At run time the model only prepares the inputs, and the verified function is called to produce the answer.

The problem: LLMs struggle with long rule chains

RuleArena (Zhou et al., ACL 2025) tests whether a model can read a rulebook and apply it to a case. The benchmark pairs three real-world rulebooks with 816 problems, each a scenario with a ground-truth answer scored by exact match. The rules are transcribed verbatim from the primary sources: the 2023 NBA Collective Bargaining Agreement, the IRS Form 1040 instructions, and the American Airlines checked-baggage policy.

A single case from each domain shows what the task looks like in practice:

NBAIs the sequence allowed? (benchmark case comp_2[25])
Prompt
Team salaries: A $80M, C $80M, D $178M. Player A, off a 4-year $24M-a-year deal with Team C and named All-NBA Second Team in 2023–24, qualifies for a maximum salary. Four more players hold contracts of $7M to $33M a year. Applied in order: (A) Team A signs free agent E to 2y/$10M. (B) Team C signs A to 3y/$42M and immediately sign-and-trades him to Team D for Players B and C. (C) Team D signs free agent D to 2y/$5.15M.
[Attached: reference rules, 461 lines of 2023 NBA Collective Bargaining Agreement excerpts, 54 rules.]
Answer
Not permitted. Operations A and B are legal, including the $42M sign-and-trade. The violation is operation C: Team D, already at $178M, has no salary-cap exception that lets it add a $5.15M outside free agent.
TaxIncome tax owed or refund (benchmark case comp_2[4])
Prompt
Married couple filing jointly, one qualifying child, three other dependents, itemising. Wages of $105,595, a $13,577 business sale, unemployment, and further income across interest, dividends, IRA, pension and Social Security. Education expenses for three students, AMT, and a dozen Schedule 1–3 adjustments and credits. Federal tax withheld: $17,750.
[Attached: reference rules, 1,158 lines of IRS Form 1040 instructions, schedules and worksheets, 31 rules.]
Answer
A refund of $16,751.15. Reaching it takes the qualified-dividends worksheet's split rates, the $10,000 state-and-local-tax cap, the 7.5%-of-AGI medical floor (which zeroes this couple's $8,832 of expenses), the child tax credit plus the credit for other dependents, and the statutory ordering of the rest of the credit stack.
AirlineTotal trip cost (benchmark case comp_2[4])
Prompt
Business-class passenger, Seattle to Wuhan, eleven itemised bags (first: a 21 × 14 × 8 inch backpack, 12 lb), $1,305 ticket.
[Attached: reference rules, 195 lines of American Airlines checked-baggage policy, 10 rules.]
Answer
$5,735 = $1,305 ticket + $1,600 base checked-bag fees + $2,830 oversize / overweight surcharges. One bag flies free as carry-on. Business class waives two base fees. Each remaining bag is $200, plus the higher (not the sum) of its oversize or overweight surcharge. Each bag over 70 lb on this China route adds $450.

None of these is conceptually deep, but each demands that the right rules be found among many and then applied without an arithmetic slip across a long chain.

The Logos approach: spec-writer, then prover

We treat a rulebook as a specification to be formalised and proved. Two AI agents build the tool once. A spec-writer reads the source text and writes each rule as a precise, typed Lean object. A prover then fills in the decision procedure, the Lean function that decides cases, and proves the stated theorems about it. The function is then packed into a Lean executable that can be called by an LLM.

At inference time the division of labour is strict. The model reads the natural-language case and extracts the inputs. The verified tool applies the rules. Nothing about the answer depends on the model getting a long, multi-step calculation right.

Results

Exact-match accuracy by model, without and with the Logos tool, 0-shot. NBA scores the official verdict triple: legality, offending operation, offending team. Tax scores the amount owed or refunded. Airline scores the exact trip cost.

ModelNBA (216) *Tax (300) †Airline (300)
Best published ‡46.7%26.7%23.3%
Claude Haiku 4.534.7% → 79.6%29.7% → 85.3%9.0% → 98.3%
Claude Sonnet 4.633.3% → 88.4%73.0% → 90.7%44.0% → 100%
Claude Opus 4.843.5% → 90.3%74.7% → 90.7%58.3% → 100%
Claude Fable 563.0% → 95.8%82.0% → 90.7%74.7% → 100%
Deterministic tool alone95.8%90.7%100%

* NBA: the remaining 4.2% traces to nine disputed answer-key cases, analysed with examples below.
† Tax: the 85–91% ceiling is set by errors in the benchmark's own answer key (corrected for them: 99.7–100%), audited with examples below.
‡ Best published: Claude 3.5 Sonnet, one-shot, tier-weighted from the paper's per-level results (Zhou et al.).

Why are the numbers not 100%? Two reasons. The benchmark's own answer key is wrong or disputed in places (28 tax cases, nine NBA verdicts), which caps even the deterministic tool. The other reason is extraction. The model preparing the inputs can misread a case. In one airline run Haiku classed Vancouver as a US city, so the tool priced the wrong route and the answer came out $5 low. Wrong input, wrong output. The rules were applied correctly to wrong facts.

Why the tool has to be verified

A natural question to ask is whether LLMs can deal with the task with any tools. RuleArena tested that directly. It let the models write their own Python and execute it, turning the interpreter into an oracle calculator for the arithmetic.

Airline task, accuracyWithout tool+ code interpreter
Llama 70B17% / 7%34% / 18%
Qwen 72B19% / 10%42% / 26%
GPT-4o32% / 16%44% / 33%

Exact-match accuracy on airline tasks at difficulty level 1 / level 2, where the model writes and runs its own Python as an oracle calculator. Source: RuleArena, Table 10. These are the paper's own models, distinct from the results table above.

The paper reached the same diagnosis. The models “still make mistakes in generated codes”. A calculator removes the arithmetic slips but not the logic errors, because the tool is improvised by the model on each query and never checked. Which fee applies, which cap exception is available, which threshold is crossed: that rule logic is still guessed.

What the proofs guarantee

“Proved in Lean” can mean several kinds of guarantee. We share three out of thirteen theorems to exemplify different aspects of proof that can ensure robustness to future edits or cases not covered by unit tests.

Computational equivalence. The tax schedule is stated twice: printed “rate × income − subtraction” rows, and the progressive accumulation they summarise. bracket proves the two agree for every filing status and every nonnegative income, so a constant inconsistent with the progressive schedule fails the proof. It failed for Head of Household filing. The mismatch traced to a threshold in the benchmark’s rule text inconsistent with both the schedule and the IRS source (see the audit section later). None of the cases in the benchmark covered this error.

Lean
theorem bracket (s : FilingStatus) (x : ℚ) (hx : 0 ≤ x) :
    bracketTax s x = progressiveTax s x

A universal numerical property. monotone proves more taxable income never means less tax, for both computations Form 1040 uses: the bracket formula, and the Line 16 procedure that reads the tax table below $100,000 and the formula above it. The proof covers every table band and the switch between the two. The table prices each $50 band at its midpoint, so the property is nondecreasing rather than strictly increasing. A constant that violates it fails the build, on every future edit.

Lean
theorem monotone (s : FilingStatus) (x y : ℚ) (hx : 0 ≤ x) (hxy : x ≤ y) :
    bracketTax s x ≤ bracketTax s y ∧ ordtax s x ≤ ordtax s y

A state invariant. NBA rules are stateful. Certain signings hard-cap a team for the rest of the season, and the engine records this as a latch on the team’s state. hardcap proves that no committed run can escape it. Starting from any state satisfying the invariant, every sequence the engine commits, of any length, still satisfies it. The proof is by induction over the run. Benchmark scenarios are about three operations long. The theorem also governs step forty, where a run that would break its latch cannot commit a final state.

Lean
theorem hardcap (cc : capconstants) (s : scenario)
    (legalStep : …) (commit : …)              -- any driver instantiation
    (init : List entry) (hInit : LatchInvariant cc init) :
    ∀ (steps : List (operation × List Nat)) (final : List entry),
      -- fold over the run: apply each step, abort on any violation
      steps.foldl applyStep (some init) = some final →
      LatchInvariant cc final

Where implementation without proof can go wrong

Wouldn't opening a coding agent and asking it to implement the rules in Python do the job?

Sometimes it would. But the RuleArena corpus shows what happens to rule implementations that nobody proves. Each of the four unproved artefacts in this story carried errors: the benchmark's reference implementation (tax), its transcribed rule text (tax), its hand-written answer key (NBA), and a small piece of unproved glue in our own stack. The proof assistant caught all four.

The tool audits the benchmark: three errors in the tax task

Run the verified calculator on all 300 structured inputs, no model in the loop, and it agrees with RuleArena's reference on 272 of 300 (90.7%). We audited all 28 disagreements by hand and attribute every one to a defect or omission in the benchmark's rule text, reference implementation, or answer key. The benchmark's code and data are public, so the audit is reproducible.

1. The answer key breaks the benchmark's own printed rule (27 of 300 cases). Form 1040 Line 22 reads "Subtract line 21 from line 18. If zero or less, enter -0-", and Line 24 adds the other taxes to it, so total tax cannot be negative. The reference implementation drops that floor. The defect is one line of micro_evaluation.py, in the function that computes the official answers:

Python
# compute_answer(), the official-answer path — no floor:
tax_payer.computed_taxes_after_credits = (
    tax_payer.f1040_line_18 - tax_payer.computed_accumulated_credits)

So whenever a taxpayer's nonrefundable credits exceed the tax they offset, the difference is paid out as a refund. The same file applies the printed floor when grading the model's intermediate steps, contradicting its own answers. Our Lean specification captures the floor where the form states it:

Lean
-- def assembly (Form 1040 lines 22–24), verified spec:
let line22 := clip (line18Form1040 - line21)  -- "if zero or less, enter -0-"
Worked examplecomp_0[21], a basic return
The only payment is $4,654 of federal withholding and there are no refundable credits, so no refund can exceed $4,654. The answer key reports a refund of $7,628, which implies a total tax of $4,654 − $7,628 = −$2,974: a negative total tax, impossible once the "enter -0-" floor is applied. The verified tool applies the floor and returns a refund of $4,465. In two further cases the key also reports a negative child tax credit (for example −$525), a second missing floor.

2. The answer key applies a rule the model was never shown: the self-employment threshold (1 of 300 cases). On the real IRS Schedule SE, Line 4c ends with a waiver: “If less than $400, stop; you don’t owe self-employment tax.” RuleArena's transcription keeps the line's arithmetic and drops the waiver. The reference enforces the waiver anyway:

Python
# compute_answer() — a rule the prompt never states:
if tax_payer.sche_se_line_4c < 400:
    tax_payer.self_employment_tax = tax_payer.self_employment_deductible = 0

This is the one case our specification misses, and it misses it deliberately. The spec is written from the prompt's rule text, and the prompt withholds the rule. Our Lean calculator therefore computes self-employment tax on any positive net earnings, exactly as the rules given to the model prescribe.

Worked examplecomp_2[81], self-employed
Net profit is $317, so net self-employment earnings are 0.9235 × $317 = $292.75, below the real-world threshold. Following the rules as printed gives a self-employment tax of 0.153 × $292.75 = $44.79. The reference uses $0. Either answer can be defended, but not both at once: the model is graded on a rule it was never given.

3. The proof exposed an inconsistency in the transcribed rulebook, confirmed against the IRS source as a transcription error (0 cases affected). Part of verifying the calculator is the bracket-identity theorem, which asserts that the published "rate × income − subtraction" bracket table computes the same function as the genuine progressive schedule. For Head of Household above $578,125 the proof failed, and the failure produced a counterexample: a 50-cent jump in computed tax at the printed threshold, which a progressive schedule cannot have. Checking the IRS source confirms the error is in the benchmark's prompt. This is the incorrect worksheet row the model is shown, in prompt.py, line 197:

text
| Over $578,125 | $TBD | × 37% (0.37) | $ 41,273.50 | $TBD | $TBD |

$578,125 is the Single filer's threshold. The subtraction $41,273.50 belongs to the genuine Head-of-Household threshold of $578,100. And the reference implementation quietly agrees with us, not with its own prompt: its bracket table uses the correct value,

Python
if filing_status == "head of household":
    cuts = [0, 15700, 59850, 95350, 182100, 231250, 578100, 1e20]

so the text shown to the model and the oracle that grades it disagree with each other, and the failed proof is what caught it.

Worked exampleThe continuity check
At the printed threshold the 35% row gives 0.35 × $578,125 − $29,711.50 = $172,632.25, while the 37% row gives 0.37 × $578,125 − $41,273.50 = $172,632.75: a $0.50 jump that a continuous progressive schedule cannot have. The printed subtraction $41,273.50 is consistent only with a threshold of $578,100, which is the genuine 2023 IRS Head-of-Household value (Rev. Proc. 2022-38). The printed $578,125 is the Single filer's threshold, copy-pasted into the wrong column.

After confirming the discrepancy against the IRS source (Rev. Proc. 2022-38), we corrected the threshold in the specification.

#ErrorWhere it livesCases affected
1Line 22 "if zero or less, enter -0-" floor omitted (two cases also show a negative child tax credit)reference implementation27 of 300
2Schedule SE $400 threshold enforced but never printed in the promptprompt vs reference1 of 300
3HoH 37% threshold listed as $578,125 instead of $578,100transcribed rule text0 of 300

There are two ways to keep score. Under our audited reading of the rules supplied to the model, the tool is right on all 300 instances and the answer key is wrong on 28 (9.3%). Judged against actual IRS law, it is correct on 299 of 300, inheriting the prompt's omission of the $400 threshold. There the key is wrong on the other 27. That is where the 99.7–100% corrected figure under the results table comes from.

The tool audits the benchmark again: nine disputed NBA verdicts

The NBA answer key is the only one produced entirely by hand. The benchmark's authors note that automated generation was infeasible for this domain. Human annotators read the CBA excerpts, wrote each scenario, decided the verdict, and listed the relevant rules, with no executable ground truth to check against.

Run the verified engine deterministically over all 216 scenarios and it reproduces 207 of the human verdicts (95.8%). We audited each of the nine disagreements individually. Our analysis attributes all nine to the answer key. Unlike the tax audit, though, arithmetic does not settle every case here.

We do not have an in-house capologist. For some of the nine, the final word is a question of CBA interpretation that we are not qualified to close.

The nine fall into two classes: four annotation defects, checkable by reading the case, and five apparent inconsistencies, where paired scenarios share every represented decision-relevant feature yet received opposite rulings (one such pair cannot both be right on arithmetic alone). We present one representative of each, as it appears in the engine's case file.

NBAThe phantom team, comp_1[62]
Scenario
Team E has a team salary of $182,000,000.
Team Q has a team salary of $95,000,000.
Team F has a team salary of $125,000,000.
Player G was the 7th first-round pick of Team A in 2015 NBA draft when he was 21 years old.
Player G signed a 3-year contract (annual salary $24,000,000, 5% increase per year) with Team Q during 2021 Moratorium Period.
Player K was the 15th first-round pick of Team B in 2014 NBA draft when he was 19 years old.
Player K signed a 3-year contract (annual salary $20,000,000, 5% increase per year) with Team F during 2022 Moratorium Period.
Player A was the 10th first-round pick of Team C in 2020 NBA draft when he was 20 years old.
Player A signed a 2-year contract (annual salary $10,000,000, 5% increase per year) with Team K during 2022 Moratorium Period.
Operations, applied in order
A. Team E signs a 2-year contract with Player A providing annual salary $5,100,000 in the first Salary Cap Year (2024-2025) and 5% increase per year.
B. Team Q signs a 3-year contract with Player G providing annual salary $35,000,000 in the first Salary Cap Year (2024-2025) and 6% increase per year, and immediately trades Player G to Team F for Player K.
Verdicts
AI engineIllegalOperation BTeam Q
Human verdictIllegalOperation BTeam H
The defect
There is no Team H. The scenario's teams are E, Q and F, and the label H appears nowhere in the case, as a team or as a player.
The AI engine's argument
The operation is illegal, but attributable to a party that exists. The signed-and-traded contract carries 6% annual raises. A sign-and-trade contract is capped at the standard 5%, because the 8% veteran allowance expressly excludes contracts signed in connection with a trade.
NBAThe hold-invocation dispute, comp_0[10]
Scenario
Team A has a team salary of $145,000,000.
Player A was the 1st first-round pick of Team A in 2010 NBA draft when he was 20 years old.
Player A signed a 5-year contract (annual salary $30,000,000, 8% increase per year) with Team A during 2019 Moratorium Period.
Player B was the 5th first-round pick of Team B in 2014 NBA draft when he was 19 years old.
Player B signed a 3-year contract (annual salary $15,000,000, 5% increase per year) with Team B during 2021 Moratorium Period.
Player C was the 5th first-round pick of Team B in 2016 NBA draft when he was 21 years old.
Player C signed a 4-year contract (annual salary $25,000,000, 5% increase per year) with Team A during 2020 Moratorium Period.
Operations, applied in order
A. Team A signs a 2-year contract with Player B providing annual salary $10,000,000 in the first Salary Cap Year (2024-2025) and 5% increase per year.
B. Team A signs a 5-year contract with Player A providing annual salary $20,000,000 in the first Salary Cap Year (2024-2025) and 8% increase per year.
C. Team A signs a 5-year contract with Player A providing annual salary $30,000,000 in the first Salary Cap Year (2024-2025) and 8% increase per year.
Provision, CBA VII.4(d)
"Until a Team's Veteran Free Agent re-signs with his Team, signs with another NBA Team, or is renounced, he will be included in his Prior Team's Team Salary" at his Free Agent Amount, 150–190% of prior salary by Bird tier.
Verdicts
AI engineIllegalOperation ATeam A
Human verdictIllegalOperation BTeam A
The AI engine's argument
Player C's Free Agent Amount is 150% of his prior salary, about $42.18M. With the hold counted, operation A must use the non-taxpayer mid-level exception at a Team Salary of $187.18M, and the post-signing total of $197.18M breaches the exception's first-apron ceiling of $178.13M.
The human verdict's implied reading
Operation A legal is only derivable hold-free, at $155.0M. The human verdict then flags operation B, the over-38 re-signing of Player A, at $180.89M. Both sides agree the scenario is illegal and agree on the team. The disagreement is which operation fails first. That is exactly the question of whether the hold counts.
The counter case, comp_0[12]
The inconsistency: the same answer key charges the hold on the same pattern. An over-cap team holding an untouched veteran free agent signs via the same exception, and the human verdict rules that signing illegal precisely because $130.0M + $49.21M + $7.2M = $186.41M breaches the same ceiling, tagging the hold rule by name. We found no deterministic reading of the supplied provisions, over the represented scenario features, that reproduces both verdicts.

The point is not that we are right. It is that our solution can be checked. All nine disagreements are laid out this way in a stand-alone case file for review by a CBA specialist. If the specialist rules against us on a case, the fix is a rule change, and we rerun all 216 scenarios before adopting it. The engine has no per-case logic. Every rule reads only the scenario's stated facts. We change a verdict only when a written provision requires it, or when a pair of cases shows that no single rule can satisfy both. Matching more of the key beyond that would mean hard-coding individual cases. On our reading, nine of the 216 verdicts (4.2%) are wrong.

Provenance: what the agents saw, and when

The audits above are only meaningful if the specifications were not derived from the artefacts they audit. The record, per domain:

Provenancedata seen during specification authoring
Tax
Specification written from the published Form 1040 instructions alone. The benchmark's reference implementation was held out by directive. It was read only afterwards, to produce the official answers at scoring time.
Airline
Same policy, verified from the session logs. Every authoring session's tool calls are persisted. The audit of that record shows the spec-writing agents never accessed the reference solver.
NBA, the method
The CBA excerpts state the rules but not their dynamics: when a cap hold attaches, what a hard-cap latch forbids later, how salaries thread through a multi-step trade. The cases are the only evidence for that layer. As in a real legal system, the statute supplies the provisions and precedent supplies their operation.
NBA, the referenced sample
71 of 216 cases (33%).
Individually diagnosed (52): comp_0 — 8, 9, 10, 12, 16, 21, 23, 26, 29, 32, 33, 35, 39, 54, 56, 68, 69, 71, 73. comp_1 — 0, 1, 2, 5, 14, 19, 21, 24, 35, 36, 49, 56, 60, 62, 64, 71, 77, 81, 82, 83, 85. comp_2 — 2, 4, 9, 10, 11, 12, 13, 16, 17, 26, 29, 34.
Sign-and-trade quantities quoted (19): comp_0 — 0, 1, 11, 28, 30, 51, 60, 62, 64, 75, 76, 77. comp_1 — 3, 26, 39, 65, 69, 73. comp_2 — 40.
The remaining 67% was never individually opened. It influenced development through aggregate accuracy counts only.
Integrity
No case-to-verdict mapping exists in the engine. Every rule is a total function of scenario features, checkable by reading the code. All nine failures fall inside the referenced third (62/71, 87.3%). On the 145 never-opened cases the engine scores 100%. The pattern weighs against case-to-verdict memorisation, though it cannot rule out subtler benchmark-informed development.
Scoring
Tax answers are graded within $1 for every model, so answers rounded to whole dollars count. Rounding to whole dollars is standard practice in real tax filing, and the allowance mainly assists the unaided models, since the tool answers in exact cents.