arXiv:2610.29228cs.AIOct 2026

Manuscript Offprint

arXiv:2610.29228

From Scores to Safe Sets: Exact Safety--Constrained Decoding for Medication Recommendation

Animesh Agarwal, Meysam Ghaffari, Nina Fatehi, Anushka Swarup, Carlos Morato

Abstract

Recent generative medication recommendation systems ultimately produce sets of drugs, but drug–drug interaction (DDI) constraints depend on the set as a whole. A natural post-hoc approach is to first predict medications and then locally repair interacting pairs by removing one drug at a time. We ask whether this local repair step itself introduces avoidable error. Using fixed medication scores from FLAME’s frozen classifier on MIMIC-III, we compare increasingly strong local repair strategies with an exact global decoder while holding the scores, output size, and DDI constraint fixed. The global decoder jointly selects the highest-scoring feasible medication set using mixed-integer linear programming. Across validation and test splits, global decoding consistently achieves higher Jaccard similarity than greedy repair, degree-aware repair, and degree-aware repair strengthened with exhaustive 1-swap local search. Its advantage is small under loose DDI constraints and becomes larger as the constraint tightens; on the test split it reaches +0.0064 Jaccard over the strongest local baseline at the strict DDI operating point. The finding also holds across a fine accuracy–DDI sweep at matched realized DDI exposure and under three score representations. At the strict setting, global decoding retains more true-positive medications while removing more false positives. These results show that medication recommendation is not only a representation-learning problem: even with a frozen clinical model, how its scores are converted into a constrained medication set can materially affect the final prediction.

1 Introduction

Medication recommendation from electronic health records (EHRs) is a canonical set-valued prediction problem. Given diagnoses, procedures, and longitudinal context, a model must recommend a combination of medications rather than a single label. This distinction matters because interactions are relational, duplicate or incompatible therapies arise at the set level, and the predicted medication set may need to satisfy multiple constraints simultaneously. A large literature has therefore developed increasingly structured medication recommenders, including sequence models, memory networks, graph-augmented models, molecular encoders, set-to-set predictors, causal representations, multimodal models, and more recently large-language-model (LLM) systems [Zhang et al., 2017, Le et al., 2018, Shang et al., 2019b,a, Yang et al., 2021a,b, Wu et al., 2022, Tan et al., 2022, Wu et al., 2023, Yang et al., 2023, Chen et al., 2023, Zhao et al., 2024, Kim et al., 2024, Li et al., 2024, Tan et al., 2024, Liu et al., 2024, Li et al., 2025, Wu et al., 2025, Zhao et al., 2025, Fan et al., 2025, Lv et al., 2026, Huh et al., 2026]. A recurring objective across this literature is to preserve recommendation

*Correspondence to: carlos.morato@optum.com

GenAI for Health Workshop @ NeurIPS 2026, Sydney.

accuracy while reducing harmful drug–drug interactions (DDIs) [Shang et al., 2019b, Yang et al., 2021b, Tan et al., 2022, Wu et al., 2023, Yang et al., 2023, Chen et al., 2023].

Throughout this paper, references to “safety” refer only to the benchmark DDI constraint used in the evaluation. They should not be interpreted as establishing comprehensive clinical safety, clinical utility, or a prescribing recommendation for the resulting medication sets.

Most prior work attacks this tradeoff primarily through learning: DDI graphs are incorporated into representation learning, molecular structure is encoded to improve drug representations, DDI penalties are added to the training objective, or list-wise objectives are used to align recommendation behavior [Shang et al., 2019b, Yang et al., 2021b, 2023, Chen et al., 2023, Fan et al., 2025]. A systematic survey of medication recommendation also highlights a basic difficulty with DDI-based post-processing: removing one interacting drug can discard treatment value elsewhere in the regimen [Ali et al., 2023]. Prior work therefore mainly asks how to learn better scores or safer representations. We ask a complementary question: once a patient-specific scorer already exists, does error arise when those scores are converted into a DDI-constrained medication set? Our central finding is that it does: even strong local repair leaves measurable accuracy on the table relative to global constrained decoding. For modern generative medication recommenders, this final decoding step is the point where model-derived scores are converted into a coupled medication set.

A natural local strategy is to repair conflicts after prediction. Start from the model's preferred set, identify a DDI conflict, remove one of the two drugs, and repeat until a target DDI level is reached. A stronger heuristic considers each drug's conflict degree and removes high-degree nodes first, and stronger still, a local-search procedure repairs bad greedy commitments after the fact by searching every feasible swap. All three remain local: a removal is committed before the algorithm knows how that choice will constrain later removals and replacements.

The problem becomes combinatorial when conflicts are dense. In our evaluation regime, output sets contain approximately 27 medications on average, and a typical predicted set contains dozens of simultaneously active DDI edges. Removing one drug may resolve many edges at once but may also force the loss of a highly supported medication; retaining a high-scoring “hub” drug can make several other high-scoring medications mutually infeasible. The quality of a local decision therefore depends on the entire conflict graph, which motivates a global formulation that selects the full set jointly.

We formulate DDI-constrained decoding as a mixed-integer linear program (MILP). For each patient visit q, a frozen scorer provides one score si(q)s_i(q) per medication. We select exactly KqK_q medications to maximize the total score, subject to an explicit budget BqB_q on selected DDI edges. Every decoder returns the same number of medications and the same DDI budget, so the comparison isolates one factor: local versus global selection. Figure 1 summarizes this shared setup.

We instantiate the scorer with FLAME's released drug-level classifier, πcls\pi_{cls} [Fan et al., 2025], on MIMIC-III [Johnson et al., 2016], using the TWOSIDES-derived DDI graph released with FLAME's preprocessing [Fan et al., 2025, Tatonetti et al., 2012]. All methodological choices are made on a training split; a disjoint validation split confirms the phenomenon before a held-out test split is scored once. The three splits follow a 4:1:1 train/validation/test ratio over approximately 14,000 total visits. We compare exact global decoding with (i) greedy repair, (ii) degree-aware repair, and (iii) degree-aware repair strengthened with exhaustive 1-swap local search. Across loose, moderate, and strict DDI budgets, the ordering Jglobal>J1−swap>Jdegree>JgreedyJ_{global} > J_{1-swap} > J_{degree} > J_{greedy} holds on both validation and test. The advantage grows as the DDI constraint tightens, holds when methods are compared at matched realized (not merely target) DDI exposure across a fine budget sweep, and holds under three different score representations.

Our contributions are:

  1. A decoding-level view of DDI-constrained recommendation. We hold the patient–drug scorer, output cardinality, and DDI budget fixed and isolate the final set-selection problem.

  2. A controlled comparison of local and global decoding. We compare exact MILP decoding with greedy repair, degree-aware repair, and degree-aware repair strengthened by exhaustive 1-swap local search.

  3. Consistent and distinguishable evidence across splits and operating points. The advantage reproduces on validation and test, persists at matched realized DDI exposure over a fine DDI sweep, and holds under three score parameterizations.

Figure

Same model scores. Same set size. Same DDI constraint. Only the decoding strategy changes.

Figure 1: Controlled comparison of local repair and global DDI-constrained decoding. A frozen FLAME scorer produces patient-specific medication scores s(q)s(q). All decoding methods use the same scores, desired output cardinality KqK_q, drug–drug interaction (DDI) graph G, and patient-specific DDI budget BqB_q. Local methods construct or repair the medication set through sequential decisions, whereas the exact MILP jointly selects the entire set to maximize the frozen model score while satisfying the same cardinality and DDI constraints. The resulting medication sets are compared using set accuracy and achieved DDI rate. Thus, the experiment isolates the effect of the decoding strategy while keeping the underlying model scores and DDI constraints fixed.

  1. A mechanistic account. Under strict DDI-constraint pressure, global decoding retains more true positives while removing more false positives, consistent with the cost of locally committing to coupled medication choices.

References (29)