SafeRx-Agent: A Knowledge-Grounded Multi-Agent Framework for Safe and Explainable Medication Recommendation

Xinyu Wang, Hanwei Wu, Zhenghan Tai, Sicheng Lyu, Qincheng Lu, Ziyu Zhao, Jijun Chi, Jingrui Tian, Xiao-Wen Chang, Ziyang SongarXiv 2026

TL;DR

SafeRx-Agent is a novel knowledge-grounded, multi-agent LLM framework designed to recommend safe and explainable medication sets from electronic health records (EHRs). By introducing a fine-grained prediction task (ATC-L4 level) and combining specialty-aware agents with a strict safety-verification loop, it matches or outperforms traditional deep learning models while drastically reducing dangerous drug interactions and contraindications.

What Problem Does This Paper Address?

Recommending medications based on a patient's ICU history is a high-stakes clinical task. Traditional deep learning approaches rely purely on structured EHR codes, completely ignoring rich clinical text narratives and external medical evidence. Conversely, while Large Language Models (LLMs) excel at processing unstructured text, they are prone to hallucinations, guideline misalignment, and prescribing unsafe drug combinations.

Furthermore, existing benchmarks evaluate models using broad medication categories (Anatomical Therapeutic Chemical third-level codes, or ATC-L3). This coarse granularity lumps distinct drug subgroups together, distorting safety evaluations and overestimating drug-drug interaction (DDI) risks. The authors tackle both challenges: they introduce a highly detailed, fine-grained medication recommendation task (ATC-L4 level) and build a reliable, multi-agent framework to solve it safely.

Methods

The authors introduce SafeRx-Agent (Safe Prescription Agent), which breaks down the clinical reasoning process into a structured, multi-agent pipeline:

  1. Expert Router: Instead of querying a massive panel of medical experts for every case, a sparse router activates only relevant specialty experts (e.g., Cardiovascular, Endocrine) based on the patient's diagnostic codes, alongside an always-on Universal Supportive Care expert.
  2. History Summarizer: Activated experts extract and structure domain-specific evidence from long, messy patient records into compact, typed summaries and visit rationales.
  3. Medication Generator: Experts propose fine-grained ATC-L4 medication candidates grounded in the patient's summary and the MEDI indication database.
  4. Global Critique: An attending physician agent reviews all expert proposals collectively, merging duplicates and pruning weak or unsupported candidates.
  5. Safety Verifier: A two-phase safety module scans the candidate drugs against external clinical databases (TWOSIDES for DDIs and openFDA for contraindications). An LLM pharmacist then adjudicates whether to retain or remove flagged drugs based on specific patient context (such as whether a drug was previously tolerated).
Figure 1: Overview of SafeRx-Agent. A patient record is routed via weighted ICD-chapter and keyword scoring to a sparse subset of specialty experts plus an always-on supportive-care expert. Each activated expert summarizes the patient record from its specialty scope and generates ATC-L4 medication candidates grounded in MEDI and the ATC taxonomy. A global Critique then judges and reconciles the expert proposals under the full patient context to produce a candidate set. A two-phase Safety Verifier retrieves DDI and contraindication evidence (MDDI, MContra) and adjudicates each flag in context, yielding a traceable ATC-L4 prescription with per-medication rationales.

Datasets

The framework was evaluated on two widely used, real-world clinical datasets:

  • MIMIC-III: A cohort of 901 patients.
  • MIMIC-IV: A cohort of 1,586 patients.

Crucially, the authors normalize all medications to the ATC-L4 taxonomy, establishing a new, fine-grained benchmark that moves beyond the traditional, coarser ATC-L3 classification.

Key Insights and Ideas

  • Granularity Distorts Safety Metrics: Evaluating safety at the coarse ATC-L3 level artificially inflates the apparent risk of drug-drug interactions and contraindications. Moving to the finer ATC-L4 level preserves critical subgroup distinctions, preventing the overestimation of safety risks.
  • The Power of Corroboration: The global critique stage acts as an incredibly effective precision filter. The authors found that 96.2% of the medications removed during the critique stage were proposed by only a single expert, proving that multi-expert consensus is a strong proxy for clinical correctness.
  • Contextual Safety Adjudication: Rather than blindly blocking every flagged drug interaction, the safety verifier mimics real clinical workflows by evaluating context. For instance, if a patient has safely taken a flagged DDI pair in a prior visit, the system biases toward continuing the treatment.
Figure 3: Binary DDI and contraindication rates under ATC-L4 and ATC-L3 medication vocabulary.

Key Results

  • Superior Accuracy: Without any task-specific fine-tuning, SafeRx-Agent matched or exceeded supervised deep learning baselines (like GAMENet and SafeDrug) on F1 and Jaccard scores across multiple LLM backbones (including GPT-5.2, Claude Sonnet-4.6, Qwen3-32B, and Gemma3-27B-IT).
  • Enhanced Safety: The explicit safety-verification loop dramatically lowered safety risks. For example, using the GPT-5.2 backbone on MIMIC-IV, SafeRx-Agent reduced the binary DDI rate from 0.7218 (unfiltered direct prompting) to 0.2819.
  • Realistic Prescription Sizes: Unfiltered LLMs tend to over-prescribe, but SafeRx-Agent's critique and safety loops successfully pruned false positives, bringing the final recommended set size much closer to real-world ground truth.
Figure 2: Diagnostic and expert analyses. (a) Critique substantially reduces average false positives. (b) Critique primarily removes medications proposed by only one expert, and effectively removes false-positives. (c) Leave-one- expert-out subgroup performance; expert abbreviations are defined at the beginning of Appendix G.

Limitations and Future Work

  • Knowledge Dependency: The framework's safety verification relies heavily on the coverage and accuracy of the underlying external databases (TWOSIDES and openFDA) and the mappings to the ATC-L4 taxonomy.
  • Lack of Prospective Validation: The evaluation was entirely retrospective and offline. Deploying SafeRx-Agent in a real hospital setting would require prospective clinical trials and strict physician oversight to guarantee patient safety.
  • Implicit Clinical Reasoning: The model still struggles with "false negatives"—medications whose indications require implicit clinical reasoning or context-dependent decisions (like vaccines or context-specific antifungal prophylaxis) that are not explicitly documented in the structured EHR.

Summary updated

BibTeX
@misc{wang2026saferx,
  author = {Xinyu Wang and Hanwei Wu and Zhenghan Tai and Sicheng Lyu and Qincheng Lu and Ziyu Zhao and Jijun Chi and Jingrui Tian and Xiao-Wen Chang and Ziyang Song},
  title = {{SafeRx-Agent: A Knowledge-Grounded Multi-Agent Framework for Safe and Explainable Medication Recommendation}},
  year = {2026},
  eprint = {2605.29146},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.29146},
}
Figure