Authors’ overview
Though patients are increasingly granted digital access to their electronic health records (EHRs), existing interfaces may not support precise, trustworthy answers to patient-specific questions. Large language models (LLM) show promise in clinical question answering (QA), but retrieval-based approaches are computationally inefficient, prone to hallucination, and difficult to deploy over real-life EHRs. This work introduces FHIRPath-QA, the first open dataset and benchmark for patient-specific QA that includes open-standard FHIRPath queries over real-world clinical data. A text-to-FHIRPath QA paradigm is proposed that shifts reasoning from free-text generation to FHIRPath query synthesis. For o4-mini, this reduced average token usage by 391x relative to retrieval-first prompting (629,829 vs 1,609 tokens per question) and lowered failure rates from 0.36 to 0.09 on clinician-phrased questions. Built on MIMIC-IV on FHIR Demo, the dataset pairs over 14k natural language questions in patient and clinician phrasing with validated FHIRPath queries and answers. Empirically, the evaluated LLMs achieve at most 42% accuracy, highlighting the challenge of the task, but benefit strongly from supervised fine-tuning, with query synthesis accuracy improving from 27% to 79% for 4o-mini. These results highlight that text-to-FHIRPath synthesis has the potential to serve as a practical foundation for safe, efficient, and interoperable consumer health applications, and the FHIRPath-QA dataset and benchmark serve as a starting point for future research on the topic. The full dataset and generation code can be accessed at:
Introduction
Over the past decade, healthcare systems worldwide have adopted standardized, interoperable representations of electronic health records (EHRs). HL7 Fast Healthcare Interoperability Resources (FHIR) has emerged as the dominant framework, with national adoption across major EHR vendors and mandated API requirements in jurisdictions such as the United States.
However, digital access does not equal understanding. Although patients can increasingly view their EHRs, FHIR’s graph-structured design makes navigation difficult. Most systems rely on keyword search, often returning entire documents or dense tables rather than the specific value requested. Bridging this gap requires automated question-answering (QA) systems capable of retrieving precise, verifiable answers from a patient’s own record.
Large Language Models (LLMs) demonstrate strong clinical reasoning on general medical QA tasks. However, deploying them over patient-specific EHR data introduces substantial challenges. Context windows are finite, making full-record ingestion costly and prone to degradation as length increases. Retrieval-Augmented Generation (RAG) systems remain vulnerable to hallucination, which is unacceptable in patient-facing tools where incorrect answers may influence health decisions. Additionally, LLMs struggle to reliably traverse FHIR’s deeply nested graph structure; benchmarks such as FHIR-AgentBench report consistent failures in multi-hop reasoning and reference resolution. Finally, transmitting sensitive patient data to external models raises privacy concerns, while hosting sufficiently powerful models locally is often impractical.
Related Work
Early EHR QA focused on Text-to-SQL generation for clinician analytics. MIMICSQL, EHR-SQL, and EHR-SQL-2024 established strong baselines using real clinical questions grounded in the MIMIC-III, eICU and MIMIC-IV databases. However, these systems rely on direct database access (SQL), which is typically inaccessible from patient-facing applications. Further, these databases have non-standard schema, so transferability to clinical use is limited.
There are limited benchmarks for QA models on FHIR. curated one of the first question-query-answer data sets in FHIR data. However, they did so using Synthea, a synthetic data-generation pipeline, so the EHRs lack the noise, variability, and scale of real clinical data. A cited study similarly used Synthea to generate a QA dataset for fine-tuning LLMs, but these questions were generated after selecting a small set of relevant resources, further simplifying the task. Consequently, systems are not required to reason over large, longitudinal EHRs with the complexity or scale of real patient records.
More recently, a paradigm shift toward agentic interaction has led to benchmarks that evaluate an LLM’s ability to interact with live FHIR servers. MedAgentBench assesses end-to-end task completion across 10 clinical workflows using 300 physician-authored questions, emphasizing practical correctness. FHIR-AgentBench similarly evaluates agentic performance, but focuses specifically on clinician-oriented question answering. Correctness is determined using annotated keys of relevant resources. While this benchmark meaningfully advances QA evaluation on real FHIR data, it does not expose or supervise the executable query logic used to retrieve answers, as the underlying dataset generation relies on SQL. Consequently, the intermediate reasoning required to traverse FHIR graphs is not directly observable or learnable, highlighting the absence of benchmarks that expose executable query logic over real FHIR data.
Data Source
To ensure questions, queries, and answers are realistic, patient data was used from the MIMIC-IV on FHIR Demo Dataset. Though the released dataset draws from the 100-patient EHRs in MIMIC-IV on FHIR Demo, the generation code extends to the full MIMIC-IV dataset. This data was uploaded into a local instance of the HAPI FHIR server as it is a robust open-source implementation of the HL7 FHIR standard.
Dataset Assembly
To ensure questions have answers (e.g. not asking about ICU visits if the patient has never been in the ICU), questions and queries were randomly generated based on the context of specific patients’ entire EHR. To account for date shifts in the de-identification process of MIMIC-IV, datetime filtering was computed with the current date being the date of the last record in the EHR. Queries were then executed against patient bundles to generate the corresponding answers.
Evaluation Splits
The dataset is partitioned into training (78%), validation (9%), and test (13%) splits using a stratified split over natural language paraphrases. Paraphrases are disjoint across splits, while question templates and patients may overlap. This setting evaluates linguistic generalization and is used for all baseline comparisons.
A query holdout is defined, in which four entire question templates are excluded from training. These templates correspond to executable FHIRPath queries that do not appear elsewhere in the dataset, while still operating over FHIR resource types observed during training. It accounts for 155 samples in FHIRPath-QA Benchmark. Performance on this split evaluates a model’s ability to synthesize novel executable query logic from natural language, rather than relying on memorized template-level mappings.
To assess structural generalization beyond the observed schema, a resource holdout is defined consisting of five templates that require FHIR resources not present in the training data, specifically Location and MedicationAdministration. This holdout is composed of 126 samples in FHIRPath-QA Benchmark. Success on this split indicates whether fine-tuning enables generalization of FHIRPath syntax and traversal patterns to unseen resource types, despite no exposure to their schemas during training.
Dataset Makeup
Volume and Diversity: In total, the dataset comprises 14,295 unique samples derived from 61 question templates and 2,095 paraphrases (~34.3 per template) which are grounded in 100 real patient EHRs. Each sample is annotated with the paraphrase split label and an indicator for belonging in the unseen query and resource-level holdout groups for simple filtering that ensures large-scale training sets are disjoint from the evaluation benchmarks.
Experiments
Experiments were designed and carried out with the following goals in mind: (1) to compare the performance and token-efficiency trade-offs between query-first (text-to-FHIRPath) and retrieval-first approaches; (2) to assess the robustness of these approaches to the variations in patient and clinician-speech; and (3) to investigate the extent to which SFT enables generalization across novel paraphrases, unseen FHIRPath logic, and novel FHIR resource types. All evaluation results in this paper are reported on FHIRPath-QA Benchmark.
Metrics
Final answer accuracy was used to evaluate model performance. This is assessed as an exact match of the executed result for the query-first approach. Since the retrieval-based approach produces free-text answers, responses were manually evaluated for correctness against the execution-validated benchmark by two independent annotators (the first and second author), both with graduate-level training and relevant domain experience. Any disagreements were resolved through discussion and consensus.
Because all experiments were conducted in the single-turn setting, failures occurred for both approaches. For large patient EHRs, the retrieval-first approach occasionally exceeded the model context limit. For the query-first approach, failures corresponded to invalid FHIRPath syntax. The accuracy excluding these failures was also measured. When failures were included, they were treated as an incorrect answer.
Fine-tuning Protocol
To evaluate the impact of specialized training, 4o-mini, 4.1-mini, and 4.1-nano models were fine-tuned on the training samples of FHIRPath-QA Large excluding all samples associated with the unseen query structure and resource-level holdout templates. Training was conducted through the OpenAI API (1 epoch, batch size 5, learning rate 1.8 for 4o-mini, 2.0 for 4.1-mini, and 0.1 for 4.1-nano). Evaluation was conducted on paraphrases in the test split to assess linguistic generalization (Test 1), on the unseen queries to assess an improved understanding of FHIR elements (Test 2), and finally on unseen resource types to assess resource-level generalization (Test 3).
To explore the effect of the number of patients represented by the training examples, SFT was performed with three subsets of the training dataset containing: 1) 10 patients, 2) 30 patients, and 3) the full 100 patients in MIMIC-IV on FHIR Demo.
A Challenging Benchmark
Notable differences in performance based on question phrasing and system architecture were observed. Retrieval-first scored more highly on clinician over patient paraphrases, which suggests that foundation models rely heavily on lexical overlap. Technical terms in clinician queries may act as anchors to the formal strings found within the FHIR resource JSONs, allowing for more accurate “needle-in-a-haystack” retrieval. Conversely, in the query-first setting, patient-perspective questions yielded higher accuracy.
Impact of Supervised Fine-Tuning
Test 2 demonstrates model capacity for logical generalization, which utilized entirely novel question templates composed of clinical reasoning elements seen in other contexts. Performance gains across all models in this category suggest that SFT enabled the agents to learn compositional mappings between clinical intent and the FHIR schema, rather than simply memorizing question–query pairs.
The results of Test 3 highlight a limit of text-to-FHIRPath generalization. As the models were tasked with querying resources not present in the training set, performance decreased following fine-tuning. While the models become highly proficient in the specific resource types and query patterns represented in the training data, they may overfit to that subset and lose some of the broader, general-purpose schema knowledge present in the base models.
The scale of patient-specific data used during training also proved to be a critical factor in model proficiency. By comparing models fine-tuned on subsets of 10, 30, and 100 patient records, a consistent upward trend in execution accuracy as the diversity of patient data increased was observed. This suggests that the current performance has not yet reached a plateau; rather, it indicates that future work extending the fine-tuning dataset to the full MIMIC-IV-FHIR corpus would likely yield further gains in handling the natural variance and “noise” found in real-world longitudinal records.
Resource Profile Complexities
A common error mode identified in generated queries stems from an apparent misunderstanding of various FHIR resource profiles. Agents frequently attempt to reference resource elements that do not exist. This failure is indicative that the structure of the resource is not fully understood by the model. For instance, Location resources do not contain temporal information, but some queries tried to access it in search of the time period of a specific visit (Appendix C.2). The correct way to access these types of resources would be to resolve the reference to it, typically via the Encounter resource.
Semantic Misinterpretation
A common failure mode arose when the models were faced with question ambiguity, resulting in syntactically correct FHIRPath that does not correctly address the question. This challenge was more prominent in patient-paraphrased questions lacking precise clinical language. For example, in questions inquiring about a patient’s medications, a particular challenge is in differentiating MedicationRequest resources (prescriptions) and MedicationAdministration (in-hospital drug administration) resources (see Appendix C.3). Resolving this ambiguity often requires clinical knowledge of whether certain drugs are typically administered in hospital or prescribed. Other subtle misinterpretations include counting total events instead of unique events (Appendix C.4) or considering in-hospital transfers as unique visits.
Conclusion
This work presents FHIRPath-QA, a novel dataset and benchmark combining patient-specific questions, validated FHIRPath queries, and executed answers. It is derived from the MIMIC-IV on FHIR Demo dataset, with clinically relevant questions expressed from both clinician and patient perspectives. To our knowledge, this is the first publicly available benchmark and dataset for Text-to-FHIRPath generation grounded in real EHRs.
Empirical comparison of retrieval-first and query-first QA pipelines shows that query-first approaches offer practical advantages in reliability and efficiency when operating over large EHRs. Executing symbolic queries avoids context window limitations, reduces token consumption by several orders of magnitude, and provides a clear and interpretable failure mode when query generation is unsuccessful. At the same time, empirical results demonstrate that retrieval-based approaches remain competitive in answer accuracy when relevant resources can be ingested, underscoring that query-first execution is not a universal replacement for retrieval-based QA.
These findings show that mapping natural language questions to executable FHIRPath logic remains challenging for pretrained LLMs. However, SFT on question–query pairs substantially improves performance and enables generalization to novel paraphrases and previously unseen question compositions over known FHIR resource types.
Limitations
This dataset is constructed from MIMIC-IV on FHIR Demo and primarily reflects ICU and in-patient care from a single institution, which may limit generalizability to other clinical settings. Although patient-oriented paraphrases are included, questions are synthetically generated from templates and may not fully capture the variability and scope of real patient-authored queries. The scope of FHIRPath-QA is restricted to factual, record-grounded questions that can be answered deterministically from structured FHIR resources; interpretive or explanatory clinical questions are out of scope. Finally, SFT experiments cover a limited set of resource types, and reduced performance on unseen resources suggests potential over-specialization.
C.1. Example 1
Model: query_gen-4.1-nano_100 Question: until last year, for patient 10003400, what was the last time a medication was prescribed using the IV route? Context: Assume current datetime is 2137-09-02T19:17:11 true_query: Bundle.entry.resource.where(resourceType=’MedicationRequest’anddosageInstruction.route.coding.code=’IV’andauthoredOn.toDateTime<=@2136-12-31T19:17:11.000Z).sort(authoredOn).last.authoredOn.toDateTime model_query: Bundle.entry.resource.where(resourceType=’MedicationRequest’anddosageInstruction.route.coding.code=’IV’andauthoredOn.toDateTime<=@2137-12-31T19:17:11.000Z).sort(authoredOn).last.authoredOn.toDateTime true_answer: 2136-12-14T08:52:22-05:00 model_answer: 2137-09-02T13:45:41-04:00 Analysis: The model used the incorrect date in the generated query despite having an exact match otherwise.
C.2. Example 2
Model: query_gen-4o-mini_100 Question: Can you tell me what the last careunit was until 2144? Context: Assume current datetime is 2145-01-03T20:33:00 true_query: Bundle.entry.resource.where(resourceType=’Encounter’andselect((period.start|period.end).sort.first.toDateTime)<=@2144-12-31T05:02:42.000Z).sort(period.start).last.location.sort(period.start).last.location.resolve.name model_query:Bundle.entry.resource.where(resourceType=’Location’andname.existsandperiod.start.toDateTime<=@2144-12-31T23:25:29.000Z).sort(period.start).last.name true_answer: Cardiac Vascular Intensive Care Unit (CVICU) model_answer: Analysis: The generated query does not demonstrate knowledge about the structure of a Location or Encounter resource. Location resources contain no temporal information; they are linked to Encounters which contain visit information including the time period.
C.4. Example 4
Model: query_gen-4.1-mini_100 Question: I need to know how many medications were issued to me until 4 months ago. Context: Assume current datetime is 2151-01-15T23:17:00 true_query: Bundle.entry.resource.where(resourceType=’MedicationRequest’andauthoredOn.toDateTime<=@2150-09-30T23:17:00.000Z).select(medicationReference.resolve|medicationCodeableConcept).distinct.count model_query: Bundle.entry.resource.where(resourceType=’MedicationRequest’andauthoredOn.toDateTime<=@2150-09-30T23:17:00.000Z).count true_answer: 258 model_answer: 1442 Analysis: The generated query counts the total number of prescriptions instead of counting distinct medication types as the question required. The result is a partially correct query.
C.6. Example 6
Model: query_gen-4.1-mini_base Question: Provide the number of Condom Cath outputs associated with patient 10035631 since 10 years ago Context: Assume current datetime is 2116-03-12T07:45:00 true_query: Bundle.entry.resource.where(resourceType=’Observation’andcode.coding.display=’CondomCath’andeffectiveDateTime.toDateTime>=@2106-01-01T07:45:00.000Z).count model_query: Bundle.entry.resource.where(resourceType=’Observation’andcode.coding.display=’CondomCath’andeffectiveDateTime.toDateTime>=@2106-03-12T07:45:00.000Z).count true_answer: 1 model_answer: 1 Analysis: The generated query uses the incorrect date component, making the correct evaluated answer coincidental.
C.7. Example 7
Model: query_gen-o4-mini_base Question: How many times was patient 10000032 given Sodium Polystyrene Sulfonate until 2180? Context: Assume current datetime is 2180-08-10T22:48:00 true_query: Bundle.entry.resource.where(resourceType=’MedicationRequest’and(medicationReference.resolve.identifier.where(value=’SodiumPolystyreneSulfonate’).existsormedicationCodeableConcept.coding.code=’SodiumPolystyreneSulfonate’)andauthoredOn.toDateTime<=@2180-12-31T22:18:53.000Z).count model_query: Bundle.entry.resource.where(resourceType=’MedicationAdministration’andmedicationCodeableConcept.coding.display=’SodiumPolystyreneSulfonate’andeffectiveDateTime.toDateTime<=@2180-12-31T22:48:00.000Z).count true_answer: 4 model_answer: 0 Analysis: The generated query has no correct components. Likely stemming from ambiguity in the question with the phrase “given Sodium Polystyrene Sulfonate”, the model assumes this to be a drug administered in a hospital context.


