arXiv:2609.10728cs.AISep 2026

Manuscript Offprint

arXiv:2609.10728

Towards a Deterministic Math Solver for Clinical Language Models

Felipe Ocampo Osorio, Sebastián Andrés Cajas Ordoñez, Maximin Lange, Rafi Al Attrach, Sahil Kapadia, Zakaria Laouabdia Sellami, Angelo Antonio Talio, Leo Anthony Celi

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Felipe Ocampo Osorio

MIT Critical Data

felipeos@mit.edu

Sebastián Andrés Cajas Ordóñez

MIT Critical Data

sebasmos@mit.edu

Maximin Lange

MIT Critical Data

mlange2@mit.edu

Rafi Al Attrach

MIT Critical Data

rafiaa@mit.edu

Sahil Kapadia

UNC Chapel-Hil

sahilk@unc.edu

Zakaria Laouabdia Sellami

University of Pavia

zakaria.laouabdiasella01@universitadipavia.it

Angelo Antonio Talio

Humanitas University

angelo.talio@humanitas.it

Leo Anthony Celi

MIT Critical Data

lceli@mit.edu

Abstract

Large language models are unreliable at arithmetic, which is a problem for clinical calculators where a single numerical error changes the recommendation. The standard response is to hardcode each calculator as a validated function, one at a time. We test an alternative: the model does not calculate. Instead, it writes case-specific Python that a restricted local executor runs as a deterministic solver, and the model's task reduces to deciding how to use it. We evaluate this Program-Solve interface on MedCalc-Bench Verified (1,100 cases, 55 calculators) against direct model arithmetic and a hand-written 22-calculator library, using Qwen2.5-7B and Qwen2.5-32B-AWQ, after auditing the benchmark's formulas against current clinical guidelines and flagging 16 of 55 with version, use or coefficient concerns. With formulas and gold variables supplied and both routes reading the whole note, handing off to the solver is not a reliable advantage at 7B (75.31% against 72.02%, a paired +3.29 points with a 95% calculator-cluster interval of [−3.49,10.38][-3.49, 10.38]) but is one at 32B (90.53% against 83.47%, +7.05 [0.47, 14.60], clear of zero). The hand-written library is exact on its 440 supported cases but abstains elsewhere (40.0% overall). Adding an executor thus helps some open-weight models more than others even under matched formula, variable and note access, and is not a substitute for verified formulas or reliable variable extraction either way. Code and data: https://github.com/felipeocampoos/Towards-a-Deterministic-Math-Solver-for-Clinical-Language-Models.

1 Introduction

Automating clinical calculators such as APACHE II [1] with a language model requires selecting the formula, extracting variables from a free-text note and executing the arithmetic, on which MedCalc-Bench [2] shows models losing accuracy: Goodell and colleagues report incorrect answers in about one third of unaided ChatGPT trials across 48 calculation tasks [3]. The standard remedy is a hand-written function per calculator, each written, validated and maintained, with every case outside the set unanswerable: the evaluated 22-calculator library implements 440 of 1,100 cases, 40.0% full-set accuracy under abstention. We evaluate whether calculator-specific execution can be replaced by a general interface: the model is given the case and writes a short Python program, and a restricted

Preprint.

(a)

(b)

Figure

Figure 1: (a) The model writes a program from note, formula and variables and an executor without calculator code runs it: all 55 calculators attempted, the library implements 22. (b) Accuracy on 1,100 cases; open bar: Blind Program-Solve. Program-Solve minus Open-book arithmetic: calculator-cluster interval (Table 2) crosses zero at 7B and clears it at 32B.

executor runs it and returns a number, a date or a gestational-age tuple. The executor contains no calculator-specific functions or constants; the model translates the supplied clinical formula into code. Clinically, execution fidelity is necessary but not sufficient: the formulas a calculator encodes are themselves versioned, and several in routine use (race-free eGFR, MELD 3.0, PREVENT, the Sampson LDL equation) have replaced predecessors that benchmarks may still reward. Local serving avoids external API calls and data transmission; its unmeasured costs are in Section 4.

Related work and contribution. Program-aided reasoning has the model emit code for an interpreter [4, 5]; chain-of-thought prompting [6] is the in-context alternative. Executing that code carries a security exposure distinct from whether it is correct [7]. MedCalc-Bench formalised calculator invocation [2]; MedRaC pairs retrieval with Python execution and scores formula selection, extraction and arithmetic separately [8]; RiskAgent selects among validated tools [9]; a clinical-calculator chatbot routes to verifiable calculators [10]; MeNTi bridges calculators and agents through nested tool calling [11]; verifiable-reward training raises the aggregate [12]; decomposition adds failure points when extraction is incomplete [13]; most calculator-selection errors are comprehension errors, not arithmetic ones [14]. A code-interpreter arm compared against task-specific calculator tools found the tools more accurate [3]. AgentMD automates the tool curation we describe as a maintenance burden [15], and the coverage-accuracy trade-off a partial library exhibits is the abstention problem [16, 17]. Our contribution is a controlled comparison of case-specific program generation against direct arithmetic and the hand-written alternative, under matched formula, variable and note access. It establishes what execution does and does not fix on one benchmark; generalization to unseen formulas, languages or settings is outside its scope.

References (36)