Serialisation Strategy Matters: How FHIR Data Format Affects LLM Medication Reconciliation

Sanjoy Pator

View Original ↗
AI 導讀 technology AI 重要性 4/5

FHIR 格式換一下,Mistral-7B 藥物調和 F1 差距達 19 點:4,000 次推理的系統性格式比較

  • ≤8B 模型用 Clinical Narrative 最佳,70B 反轉用 Raw JSON;Mistral-7B 格式差距達 19 F1 點
  • 20 種組合全部 Precision > Recall:漏報藥物比捏造藥物更普遍,稽核重點應轉向完整性
  • Mistral-7B 在 11 顆活躍藥患者 Recall 跌至 0.24,多重用藥族群需要 70B 以上才能穩定應對

把 FHIR(Fast Healthcare Interoperability Resources,醫療資料互通標準)資料改成白話英文格式,Mistral-7B 的藥物調和 F1 分數從 0.72 躍升至 0.91——改的不是模型,只是輸入格式。這個結論來自 4,000 次推理實驗:5 個開源模型、4 種序列化格式、200 位合成病患,格式選擇對小模型的影響,幅度堪比換一個更大的模型。

為什麼 FHIR 序列化是被忽視的部署變數

藥物調和(medication reconciliation)是臨床交接時最高風險的操作之一:病患轉院、出院、換班,都可能讓一顆慢性病用藥從清單上消失。研究指出,超過 60% 的病患在照護轉換時發生藥物不符,其中相當比例導致可預防的不良事件。

LLM(大型語言模型)被提出協助這項工作,通常以 FHIR R4 結構化的電子病歷作為輸入。問題在於 FHIR 的原生格式是深度嵌套的 JSON,充滿 RxNorm、SNOMED 等數字代碼,單一病患的完整 FHIR bundle 可超過 80 萬行 JSON,遠超任何模型的上下文視窗。在資料送進模型之前,必須先做序列化(serialisation)——把 FHIR 轉換成模型能讀的文字格式。這個步驟幾乎不被系統性研究,卻是每個部署管線都要做的隱性決策。

四種格式、五個模型、4,000 次推理

研究設計了四種序列化策略:Strategy A(Raw JSON,原始 JSON)保留原始欄位結構;Strategy B(Markdown Table,Markdown 表格)把每筆藥物攤平成一列;Strategy C(Clinical Narrative,臨床敘事)用白話英文句子描述每筆藥物,並在最上方明確標出「目前使用中的藥物」標題;Strategy D(Chronological Timeline,時間軸)按開立日期排序所有記錄,不區分在用或歷史用藥。

評估對象包含五個開源模型:Phi-3.5-mini、Mistral-7B、BioMistral-7B、Llama-3.1-8B、Llama-3.3-70B,全部在 AWS g6e.xlarge 實例(NVIDIA L40S,48 GB VRAM)以 4-bit 量化本地運行,不使用任何商業 API。評估指標為嚴格的精確字串比對(exact string match),F1 值代表下界估計,真實環境以模糊比對會更高。

8B 以下用 Clinical Narrative,70B 反轉用 Raw JSON

格式效果的規律性令人印象深刻。對所有 ≤8B 的 instruction-tuned(指令微調)模型,Strategy C(Clinical Narrative)均為最佳格式:Mistral-7B 從 Raw JSON 的 F1 0.7247 提升至 0.9149(效應量 r=0.617,p<10⁻¹⁰,統計意義極強);Llama-3.1-8B 從 0.9180 升至 0.9471;Phi-3.5-mini 從 0.6356 升至 0.7008

排名在 70B 完全反轉。Llama-3.3-70B 在 Raw JSON 達到 F1 = 0.9956,Clinical Narrative 則為 0.9850,略遜但差距不顯著。然而 Strategy D(Chronological Timeline)在 70B 表現異常差,F1 僅 0.8742,且有 25 位病患得到零分——即使大模型對結構格式的容忍度高,對需要跨時間推理才能判斷藥物狀態的格式,仍然明顯力不從心。

5 模型 × 關鍵格式 F1 分數對比
模型Strategy A(Raw JSON)Strategy C(Clinical Narrative)格式效果
Phi-3.5-mini0.63560.7008+7 pt,差異不顯著
Mistral-7B0.72470.9149+19 pt,r=0.617,p<10⁻¹⁰
Llama-3.1-8B0.91800.9471+3 pt,r=0.345,p=0.011
Llama-3.3-70B0.9956(最佳)0.9850Raw JSON 反勝,差異不顯著
BioMistral-7B0.00000.0000全格式失效

遺漏 > 幻覺:全部 20 組 Precision > Recall

這份研究的另一個發現改變了臨床安全稽核的思維框架:在所有 20 種模型-格式組合中,平均精確率(precision)均高於或等於平均召回率(recall)。換句話說,模型漏報活躍藥物(omission,遺漏)比捏造不存在的藥物(hallucination,幻覺)更常見。

幻覺確實發生——Phi-3.5-mini 在 Raw JSON 下的精確率低至 0.73,代表約 27% 的輸出項目不在真實清單中——但在每一個測試條件下,幻覺的發生率都低於遺漏。從稽核實務的角度看,這個不對稱性意味著:模型輸出是一份部分但可信度較高的活躍藥物清單,臨床人員需要關注的問題是「模型漏了什麼」,而非同時核查假陽性和假陰性。

值得注意的是,較長的藥名被遺漏的比例更高:Mistral-7B 在 Clinical Narrative 下,遺漏的藥物中有 37% 名稱超過 50 個字元,而真陽性中只有 22% 超過此長度。被遺漏最多的單一藥物是 Hydrochlorothiazide 25 MG Oral Tablet(一線降壓藥),Mistral-7B 在 Strategy A 下有活躍此藥的 53 位病患中,漏掉了 34 位。

多重用藥瓶頸:7-10 顆以上召回率崩潰,70B 才穩

小模型在面對多重用藥(polypharmacy)病患時有一個硬性能力上限。Mistral-7B 的召回率從只有 1 顆活躍用藥時的 0.96,跌至 11 顆時的 0.24。Llama-3.1-8B 退化較緩,但在 10 顆以上仍跌至約 0.80。Llama-3.3-70B 則在 16 顆活躍用藥的情境下維持接近完美的召回率,幾乎無退化。

關鍵在於,失敗的瓶頸是輸出生成容量,不是上下文視窗:研究確認,藥物歷史年份的長度(10 年 vs 25 年以上)對召回率毫無預測力;只有目前活躍用藥的數量才會拖累召回率。模型不是讀不完輸入,而是無法在一次回答中列舉出所有活躍用藥。這對臨床部署決策有直接意義:複雜的多重用藥病患,需要 70B 等級的模型,而非靠格式優化彌補小模型的能力上限。

BioMistral 零分:領域預訓練沒有 Instruction Tuning 等於零

BioMistral-7B 在 4 種格式的所有 200 位病患上 F1 全部為 0.0000,而同樣架構與參數量的 Mistral-7B 在 Clinical Narrative 下達到 F1 0.9149。BioMistral 以 30 億 PubMed Central token 繼續預訓練,起點是 Mistral-7B Instruct v0.1,理論上應保留指令遵循能力——實際上並沒有。檢視原始輸出,發現兩種失敗模式:亂碼(113-140 位病患,依格式而定)和直接把系統提示詞複製貼上(11-68 位病患)。沒有任何一次運行產出可解析的 JSON 陣列。領域知識的深度,在指令遵循能力完全喪失的情況下毫無用武之地。

格式是部署決策,不是樣式選擇——同一個 Mistral-7B,換格式帶來 19 F1 點;稽核重點應從「模型說了什麼」轉向「模型漏了什麼」。

Abstract

Medication reconciliation at clinical handoffs is a high-stakes, error-prone process. Large language models are increasingly proposed to assist with this task using FHIR-structured patient records, but a fundamental and largely unstudied variable is how the FHIR data is serialised before being passed to the model. We present the first systematic comparison of four FHIR serialisation strategies (Raw JSON, Markdown Table, Clinical Narrative, and Chronological Timeline) across five open-weight models (Phi-3.5-mini, Mistral-7B, BioMistral-7B, Llama-3.1-8B, Llama-3.3-70B) on a controlled benchmark of 200 synthetic patients, totalling 4,000 inference runs. We find that serialisation strategy has a large, statistically significant effect on performance for models up to 8B parameters: Clinical Narrative outperforms Raw JSON by up to 19 F1 points for Mistral-7B (r = 0.617, p < 10^{-10}). This advantage reverses at 70B, where Raw JSON achieves the best mean F1 of 0.9956. In all 20 model and strategy combinations, mean precision exceeds mean recall: omission is the dominant failure mode, with models more often missing an active medication than fabricating one, which changes how clinical safety auditing priorities should be set. Smaller models plateau at roughly 7-10 concurrent active medications, leaving polypharmacy patients, the patients most at risk from reconciliation errors, systematically underserved. BioMistral-7B, a domain-pretrained model without instruction tuning, produces zero usable output in all conditions, showing that domain pretraining alone is not sufficient for structured extraction. These results offer practical, evidence-based format recommendations for clinical LLM deployment: Clinical Narrative for models up to 8B, Raw JSON for 70B and above. The complete pipeline is reproducible on open-source tools running on an AWS g6e.xlarge instance (NVIDIA L40S, 48 GB VRAM).