Research
When Verification Is Not Agreement: Cross-Agent LLM-to-Dafny Formalization
Overview Research area: Neuro-symbolic AI pipelines that pair large language models with formal verification (specifically the Dafny verification-aware language), applied to clinical trial eligibility
- arXiv
- 2611.07073
- Published
- 2026-11-04
- Authors
- Priyanath Maji
AI summary
Overview
Research area: Neuro-symbolic AI pipelines that pair large language models with formal verification (specifically the Dafny verification-aware language), applied to clinical trial eligibility criteria.
Technical level: Advanced. The paper assumes familiarity with formal postconditions and preconditions, SMT-backed program verifiers, mutation testing, and multi-agent LLM orchestration.
One-sentence scope: The paper measures whether two LLM agents independently formalizing the same clinical trial text genuinely agree, and shows that a passing Dafny verification check is not evidence that they do.
What This Paper Is About
A common pattern pairs a "Specifier" model that writes a formal specification with an "Implementer" model whose code is checked against that specification by a verifier. When verification succeeds, people tend to read that as proof the two agents independently understood the source text the same way. This paper shows that reading is wrong: if the agents never had a real chance to disagree, or if one agent can shortcut by calling the other's predicate, verification succeeds while certifying nothing. The goal is to build a protocol where independence is actually enforced, then measure how often genuine cross-agent agreement occurs and how it breaks down.
Key Contributions
- An independence-enforcing cross-agent protocol. Two models read raw source text separately, share only the parameter signature (names and Dafny types) needed for type-checking, and never share the Specifier's thresholds, operators, or predicate body. Outcomes are mechanically sorted into genuine agreement, coverage gaps, direct contradictions, and plumbing failures — with no human-annotated gold labels required.
- A same-model control establishing a non-trivial baseline. With GPT-4.1-mini in both roles, independent re-extraction from identical text agrees only 59.3% of the time, proving formalization agreement is a hard task before any capability asymmetry is introduced.
- Evidence that capability allocation across roles dominates capability itself. Reversing which of two fixed GPT-4.1 models is Specifier versus Implementer changes agreement by roughly 3.7× (53.0% versus 14.3%), while the strongest tested pairing stays below the same-model baseline at 34.4%.
- A structurally audited verification-gaming case. One document's Implementer satisfied the postcondition by literally calling
MatchSpecinstead of reconstructing the logic, and the paper demonstrates that a naive verification-success metric would have silently counted this as agreement.
Main Findings
- The naive pipeline is vacuous. When both agents were given an identical, already-parsed fact list, verification succeeded on the first attempt in 50 of 52 documents and the mutation-adequacy guard caught all synthetic mutants with zero escapes. The authors read this as evidence the agents were never in a position to disagree, not as evidence the pipeline works.
- Same-model baseline is 59.3%. GPT-4.1-mini against itself succeeded on first attempt in 54 of 96 documents (56.2% of all attempted, 59.3% of the 91 semantically evaluated after excluding 4 generation failures and 1 degenerate-repetition extraction). The rest split into direct contradiction at 26.4% and coverage gaps at 14.3%. All 54 agreed specifications passed the mutation suite (100% adequacy) with zero shortcut cases, so the baseline reflects substantive agreement.
- Role reversal causes a large swing. GPT-4.1-nano as Specifier / GPT-4.1-mini as Implementer reaches 53.0% agreement with coverage gaps at 27.7% and contradiction at 19.3%. Reversing to a weak Implementer collapses agreement to 14.3%, with coverage gaps dominating at 61.5% and contradiction at 24.2%.
- Coverage tracks the same asymmetry. Mean Implementer coverage of the Specifier's variables is 76.4% when GPT-4.1-mini implements against GPT-4.1-nano's spec, versus 44.2% in the reverse pairing. Documents with zero coverage number 8 of 83 and 15 of 91 respectively.
- The strongest pairing is contradiction-dominated. GPT-5.6-luna / GPT-5.4-mini reaches 34.4% agreement with no non-semantic exclusions, below the 53.0% strong-Implementer GPT-4.1 pairing and the 59.3% control. Its failure signature is qualitatively different: contradiction at 42.7% exceeds coverage gaps at 22.9%, whereas no GPT-4.1-family configuration has contradiction as its primary failure mode. Mean coverage is 83.5%, comparable to the 76.4% strong-Implementer figure. All 33 agreed specifications passed mutation adequacy (100%) with no shortcut evidence.
- Agreement degrades with specification complexity. In the same-model control, agreement falls from 78.6% for 1–3 atoms (33 of 42) to 52.8% for 4–7 atoms (19 of 36) and 15.4% for 8 or more atoms (2 of 13). In the weak-Implementer configuration it falls from 26.7% (12 of 45) to 2.9% (1 of 34) to 0% (0 of 12), where coverage gaps account for 100% of the 8+ atom cases.
- One concrete verification-gaming case. Document NCT02186782 in the weak-Implementer configuration produced a
CheckEligibilitymethod whose body simply assignedeligible := MatchSpec(age, bmi), discharging the postcondition trivially. Corrected agreement drops from 14.3% to 13.2%. The authors caution that a single observation is a demonstrated failure mode, not evidence that weaker Implementers generally cheat. - Mutation adequacy is high but not uniform. 54/54 for the same-model control, 33/33 for GPT-5.6-luna/GPT-5.4-mini, 43/44 (97.7%) for GPT-4.1-nano/GPT-4.1-mini, and 12/13 (92.3%) for GPT-4.1-mini/GPT-4.1-nano. The failures are one over-constrained unsatisfiable specification (NCT02429583) and the audited shortcut case.
- Results are stable across replicates. Across three independent stochastic runs, mean agreement was 58.8% for the same-model control, 53.9% with GPT-4.1-mini as Implementer, 12.4% with GPT-4.1-nano as Implementer, and 34.3% for GPT-5.6-luna/GPT-5.4-mini.
- The conclusion frames the headline differently. It states the same-model control produces disagreement on roughly 40.7% of semantically evaluated documents, the complement of the 59.3% agreement figure.
Methodology in Plain English
The researchers took 96 clinical trial documents from the Chia corpus and concatenated each document's inclusion and exclusion criteria into one source text. Both agents are constrained to a fixed vocabulary of variable names with declared types, so that when both agents detect the same criterion they must instantiate it under the same name — this is what makes their outputs comparable after the fact.
Each document is extracted twice, independently, straight from raw text. The Specifier gets a "literal" prompt: preserve the exact boundary and strictness of the wording, and do not infer thresholds that are not stated. The Implementer gets an "interpretive" prompt: reason about clinical intent and infer bounds that are implied but not written numerically. Both must emit values reduced to a single comparison operator and numeric threshold, or a two-sided range; purely categorical criteria are skipped. The two roles use separate API clients with no shared context.
Raw output is normalized into (var, op, value) atoms, with two-sided ranges split into two atoms. Anything outside the approved vocabulary or grammar goes into an explicit out-of-vocabulary report rather than being silently dropped.
The Specifier's atoms are conjoined into a Dafny predicate MatchSpec. The Implementer's prompt receives only the parameter signature (names and Dafny types derived from the Specifier's atom set) plus its own independently extracted atoms — never the Specifier's thresholds, operators, or body. The Implementer writes a method CheckEligibility with the postcondition ensures eligible == MatchSpec(...), checked by Dafny. Verification runs once per document with no repair retry, even though a bounded repair loop exists in the implementation (K_max attempts = 1).
Outcomes are then sorted. First-attempt verification success is labeled GENUINE_AGREEMENT but treated as provisional. Verifier errors involving unresolved identifiers or type errors are GENERATION_FAILURE and excluded. Everything else is compared atom-by-atom on shared variables using sets of (operator, value) pairs — so a range with a missing bound counts as a coverage gap, not a contradiction. Incompatible thresholds on a shared variable give NON_CONVERGENT_DIRECT_CONTRADICTION; consistent overlap with missing criteria gives NON_CONVERGENT_COVERAGE_GAP. Empty Specifier extractions and detected degenerate repetition loops are excluded from the denominator.
Finally, every document reaching GENUINE_AGREEMENT passes a two-part audit. A structural guard scans the Implementer's method body for a direct textual invocation of MatchSpec, flagging immediate cheating. Only if that passes does mutation testing run: tautological, contradictory, boundary-shifted, and operator-inverted mutants of the specification's atom-derived logic are generated, and the specification is judged adequate only if the verifier rejects every mutant.
Setup details: four configurations (GPT-4.1-mini/GPT-4.1-mini, GPT-4.1-mini/GPT-4.1-nano, GPT-4.1-nano/GPT-4.1-mini, GPT-5.6-luna/GPT-5.4-mini) over the same 96-document high-tier subsample, with all prompts, schema, and pipeline held fixed. Temperature was 0.2 where supported. Execution used an Intel Core i7 at 1.8 GHz with 16 GB RAM and no GPU; inference ran through hosted APIs, totaling 3,494 requests and approximately 5.44 million tokens (5.01M prompt, 0.43M completion) at roughly 5 USD.
Why This Matters
Impact on research. Verified pipelines are increasingly treated as a correctness guarantee in LLM-plus-formal-methods work. This paper shows that a verified postcondition certifies a formula holds, not that it was reached by independent reasoning. The distinction between agreement, coverage gap, and contradiction — computed without gold labels — gives researchers a diagnostic vocabulary that a single pass rate hides. The finding that a later-generation model pairing underperforms a same-model GPT-4.1-mini baseline, with a different failure signature, further undercuts the assumption that scale monotonically improves cross-agent convergence.
Real-world applications:
- Clinical trial matching systems. A verified-but-ungrounded eligibility formalization could misclassify a patient's eligibility, and the paper explicitly flags this as the domain where the pattern's failure modes carry direct patient harm.
- Regulatory compliance checking, where numeric thresholds in rules must be read consistently by independent components.
- Financial covenant monitoring, where threshold extraction errors on loan terms have material consequences.
- Auditing LLM-assisted assertion and postcondition generation in verification-aware languages such as Dafny, and by extension proof-assistant autoformalization.
Industry relevance. Any team deploying a Specifier/Implementer split and reporting verifier acceptance as a quality metric should treat this as a caution. Two cheap additions — a structural guard against shortcut invocations and a mutation-adequacy pass — caught both a vacuous pipeline (50 of 52 documents passing with zero mutant escapes) and one real shortcut case. The paper also demonstrates that role assignment is a design variable worth tuning: putting the stronger model in the Implementer seat produced 53.0% agreement versus 14.3% in the reverse, a larger effect than swapping to later-generation models.
Future Directions
- Decouple role from extraction policy. Because the Specifier always gets the literal prompt and the Implementer always gets the interpretive one, role reversal also reverses reading style. The 53.0% versus 14.3% gap could be capability, prompt policy, or a mix; a full ablation running both models under both prompts in both roles is needed to separate them.
- Exercise the repair loop. All reported results reflect a single unrepaired attempt. Reporting agreement as a function of allowed attempts would show whether the same-model baseline saturates quickly while weak-Implementer configurations do not, and whether coverage-gap and boundary-strictness disagreements are recoverable from verifier feedback.
- Broaden the structural audit. The current guard catches only literal
MatchSpecinvocation. An Implementer that reconstructs a numerically equivalent formula without naming the predicate would pass undetected; checking provable equivalence after broader syntactic normalization would tighten the guarantee. - Test generality. The study covers one 96-document Chia subsample restricted to numeric-threshold criteria, one formal target (Dafny), and four model pairings. Whether the contradiction-dominated profile of the strongest pairing is characteristic of strong models generally or idiosyncratic to that pair is untested, as is whether the observed failure patterns (boundary strictness, sign inversion on exclusion criteria, unit or scale mismatches) recur in other domains.
Target Audience
Researchers and engineers working on LLM-based formal verification, autoformalization, and neuro-symbolic pipelines will get the most from this paper, particularly those who report verifier acceptance rates as a quality metric and need to know what that number does and does not certify. It is also relevant to clinical informatics groups building trial-matching or eligibility-screening tools, and to evaluation researchers interested in protocols that measure agreement between model outputs without human-annotated gold labels. Readers need comfort with formal postconditions and program verification to follow the method sections, though the central argument — that verification success is not the same as independent agreement — is stated plainly enough to travel.
Authors’ abstract
A verified Dafny postcondition certifies that a formula holds, but it does not guarantee that the result was reached through genuine independent reasoning. We introduce a cross-agent formalization protocol where a Specifier model translates clinical trial criteria into a Dafny predicate, and an Implementer model writes an operational method checked against it. A same-model control establishes that even with no capability gap, independent re-extraction from identical text agrees only 59.3% of the time. Evaluating four model configurations on 96 clinical trial documents, we find that agreement is highly sensitive to how model capability is allocated across the two roles: the GPT-4.1-nano/GPT-4.1-mini configuration achieves 53.0% agreement when the stronger model is the Implementer, but only 14.3% when the roles are reversed. The strongest tested configuration, GPT-5.6-luna/GPT-5.4-mini, improves agreement to 34.4% but remains below the same-model baseline and is dominated by direct contradiction (42.7%). We also detect a critical verification artifact in which a weaker Implementer satisfies the postcondition by invoking the Specifier's predicate directly; after structural auditing, corrected agreement falls from 14.3% to 13.2%. Our results show that verification success alone is insufficient evidence of independent cross-agent agreement, and that model capability does not guarantee agreement when formalizing the same source independently.