[KongchangAI]
· 2 min read· 1,310 words

MedLean: Equipping Medical AI with a Formally Verified Safety World Model Using Lean 4

MedLean: Equipping Medical AI with a Formally Verified Safety World Model Using Lean 4

MedLean uses Lean 4 to formalize clinical guidelines, providing an interactive safety verification kernel for multimodal large language models.

MedLean is a study aimed at restarting formal medical verification. It proposes a two-stage architecture: an offline compiler compiles four NCCN/CSCO oncology guidelines into 1,861 executable rules and uses Z3 for full-space auditing, discovering 362 binary negative-default leaks and guideline contradictions; an online verification kernel with 23 machine-checked theorems intercepts violating outputs during inference. On 428 multi-cancer cases, high-risk outputs dropped to 0% and certification rates reached 98.4% and 100%. The study also reveals that binary rule engines lower mandatory-obligation completion, and safety-first models' conservative omission requires a consultation-goal accountability mechanism. MedLean positions formal verification as an interactive safety world model for MLLMs.

Large language models are increasingly adept at processing clinical text, yet they still prescribe contraindicated therapies when lab results are missing, or overlook mandatory clinical obligations. A study called MedLean attempts to reactivate the long-stalled field of formal medical verification and positions it as an "interactive safety world model" for multimodal large language models (MLLMs).

Why Formal Verification Has Long Remained on Paper

The idea of formal medical verification is not new: encode clinical guidelines as mathematical logic, and use programs to audit whether treatment plans comply. The problem lies in the cost of implementation—burdensome coding work, manual extraction of medical records, and opaque outputs have long prevented traditional tools from scaling.

On the other side, LLMs and MLLMs perform excellently in clinical text understanding but expose shortcomings in safety. The original text notes that such models still output contraindicated treatments when lab tests are missing, and omit mandatory clinical obligations. Both approaches have clear flaws, and MedLean's starting point is to make them complementary rather than substitutive.

The core idea of formal verification is to precisely describe system behavior with mathematical logic, and to determine—through algorithmic enumeration or proof—whether all possible states satisfy given properties (such as "no guideline-violating medication exists"). In the medical domain, this means transcribing conditions, contraindications, and mandatory actions from clinical guidelines into formal logical formulas, then checking treatment pathways for compliance. Traditionally this relies on theorem provers or model-checking tools, but the bottleneck lies in the gap between domain experts and formal-methods experts: the natural-language ambiguity, exception clauses, and temporal dependencies in guidelines require extensive manual modeling, and audit results are often presented as counterexample traces that clinicians find hard to interpret directly. This has kept formal medical verification stuck at small-scale pilots, unable to cover real-world guideline updates and multi-disease scenarios.

MedLean's Two-Stage Architecture

The research focuses on oncology and builds a two-stage framework based on Lean 4.

Offline Compiler and Z3 Full-Space Auditor

MedLean-Compiler covers four NCCN and CSCO guidelines, compiling a total of 1,861 executable rules, and uses Z3 for full-space auditing. The static audit phase uncovered 362 binary negative-default leaks, while also exposing genuine self-contradictions in published guidelines. This shows that formal auditing is not only an external checker for models but can also in turn verify the consistency of the guideline texts themselves.

Z3 is a high-performance SMT (Satisfiability Modulo Theories) solver developed by Microsoft Research, capable of determining whether first-order logic formulas are satisfiable under specific theories (such as integer arithmetic, arrays, and bit-vectors). In MedLean, Z3 is used for "full-space auditing": the compiled rules and guideline constraints are encoded as logical formulas, and the solver then systematically searches for assignments that violate the constraints (i.e., potential loopholes in treatment plans). The so-called "binary negative-default leaks" refer to the situation in default logic where, when a certain condition is not explicitly satisfied, the system incorrectly defaults it to false (negative default), thereby permitting operations that should have been prohibited; Z3 can precisely capture such violations and provide counterexamples. Compared with manual testing, full-space auditing can exhaust all combinations within a finite rule set, discovering contradictions and leaks that are hard for the human eye to notice.

Online Verification Kernel

MedLean-Verifier is a verification kernel for online inference, supported by 23 machine-checked theorems. Its role is to intervene in real time as the model generates treatment plans, intercepting outputs that do not comply with the rules, rather than remediating after the fact.

The key difference between the online verification kernel and offline auditing lies in timing and interactivity. Offline auditing targets a static rule set, whereas online verification needs to check in real time whether each step violates existing theorems as the model generates a treatment plan step by step (such as a chain of thought or a sequence of tool calls). The 23 machine-checked theorems in MedLean-Verifier are essentially formally proven safety invariants, for example, "if a certain test result is missing, then a certain class of contraindicated drugs must not be prescribed." These theorems are compiled into quickly executable checkers that intercept violating outputs during inference, rather than performing post-processing after the complete plan is generated. This "verify-while-generating" mode reduces the risk of error accumulation and also enables the model to adjust its subsequent generation strategy immediately based on interception signals.

Empirical Results: High-Risk Outputs Driven to Zero

The study tested two models, DeepSeekAd-V4.1-Flash and GPT-6.2-Astra, on 428 multi-cancer cases. After integrating MedLean, the proportion of high-risk outputs dropped to 0%, and the overall plan certification rates rose to 98.4% and 100%, respectively.

Interestingly, the study also found that binary rule engines actively lower the completion rate of mandatory obligations, even below that of unverified LLMs. In other words, the harder the rules, the more likely the model is to sacrifice necessary clinical actions in order to comply. Safety-first models can pass basic certification, partly because they adopt a conservative omission strategy—unless a "consultation-goal accountability" mechanism is also introduced, this conservatism itself becomes a hidden risk.

The "consultation-goal accountability" mechanism targets the conservative omission behavior common in safety-first models: when the model cannot confirm whether a mandatory clinical obligation (such as a required consultation or follow-up) is satisfied, it may choose not to generate that action to avoid risk, resulting in a plan that is formally "safe" (no high-risk outputs) but clinically incomplete. The accountability mechanism requires the verification kernel to check not only "prohibited items" but also track the completion status of "mandatory items," and to explicitly mark uncompleted mandatory goals as failures rather than tacitly permitting omission. This design extends safety constraints from a one-way prohibition list to a two-way obligation checklist, forcing the model to strike a balance between compliance and completeness rather than simply drifting toward conservatism.

Implications of a Safety World Model

MedLean is not positioned to replace LLMs but to serve as their interactive safety world model: the model is responsible for understanding and generation, while the formal kernel is responsible for constraint and auditing. This division of labor is especially valuable in domains like oncology, which are rule-dense and have low tolerance for error.

The study also leaves open questions. The tension between conservative omission and mandatory obligations shows that merely pursuing "zero high-risk outputs" does not equal clinical safety; how to make the verification mechanism simultaneously constrain "what should not be done" and "what must be done" is a direction that needs to be addressed in future work. In addition, the fact that contradictions in the guidelines themselves were exposed by static auditing also suggests that formal tools can feed back into the maintenance of medical knowledge bases.

From a broader perspective, MedLean is only a "gentle step," but it demonstrates that formal verification and MLLMs can coexist within the same workflow, rather than being an either-or choice.

One-line Summary

MedLean uses Lean 4 to formalize clinical guidelines, providing an interactive safety verification kernel for multimodal large language models.

Paragraph Summary

MedLean is a study aimed at restarting formal medical verification. Addressing the high implementation costs of traditional formal tools and the insufficient clinical safety of LLMs, it proposes a two-stage architecture: an offline compiler compiles four NCCN/CSCO oncology guidelines into 1,861 executable rules and uses Z3 for full-space auditing, discovering 362 binary negative-default leaks and contradictions within the guidelines themselves; an online verification kernel, supported by 23 machine-checked theorems, intercepts violating outputs in real time during inference. On 428 multi-cancer cases, after integrating MedLean, the high-risk outputs of the two models dropped to 0%, with certification rates reaching 98.4% and 100%, respectively. The study also reveals that binary rule engines lower the completion rate of mandatory obligations, and that the conservative omission of safety-first models needs to be paired with a consultation-goal accountability mechanism. MedLean positions formal verification as an interactive safety world model for MLLMs, rather than a replacement.

#MedLean#Lean 4#formal verification#medical AI#MLLM#safety world model#oncology guidelines#Z3
Share:

Related articles