Query, Don't Train: Privacy-Preserving Tabular Prediction from EHR Data via SQL Queries

Josefa Lia Stoisser, Marc Boubnovski Martell, Kaspar Märtens, Lawrence Phillips, Stephen Michael Town, Rory Donovan-Maiye, Julien Fauqueur

TL;DR

Query, Don’t Train (QDT) is a novel framework that replaces traditional model training with LLM-generated SQL queries to perform privacy-preserving tabular predictions. By retrieving only aggregate population statistics rather than raw patient records, QDT achieves state-of-the-art performance on clinical tasks while remaining inherently interpretable and compliant with strict data regulations like HIPAA and GDPR.

What Problem Does This Paper Address?

Electronic Health Records (EHRs) are a goldmine for predictive modeling, but they are locked behind a "privacy wall." Regulations like HIPAA and GDPR strictly limit access to individual-level data, making it difficult to train centralized models or share datasets across institutions.

Traditional supervised learning (like XGBoost) requires full access to raw training data. Even modern "in-context" learners like TabPFN require raw examples to be fed into the model at inference time. This creates a fundamental tension between predictive utility and patient privacy. The authors ask: Can we build a foundation model for tabular data that makes accurate predictions without ever seeing a single raw patient record?

Methods

The authors introduce Query, Don’t Train (QDT), a two-stage framework that treats a Large Language Model (LLM) as a schema-aware query planner rather than a traditional classifier.

  1. Query Generation: When presented with a new test record (e.g., a patient’s current vitals and history), an LLM agent (OpenAI’s o4-mini) generates SQL queries designed to find "similar" cohorts in the private database.
  2. Privacy Firewall: To ensure compliance, a second LLM acts as a validator. It checks that queries only request summary-level statistics (e.g., averages or counts aggregated over at least two patients) and blocks any attempt to retrieve individual rows.
  3. Execution & Reasoning: The approved SQL runs against the database. The LLM then performs Chain-of-Thought (CoT) reasoning over these aggregate results—comparing the test patient to the retrieved population statistics—to produce a final prediction.
Comparison of TabPFN and the QDT approach. QDT uses a loop of SQL generation, privacy checking, and reasoning rather than direct data access.

Datasets

The framework was validated on a high-stakes clinical task: 30-day hospital readmission prediction for Type 2 diabetes patients.

  • Source: A MIMIC-style EHR cohort derived from a dataset of 130 US hospitals (available via Kaggle/UCI).
  • Composition: The dataset includes demographics, lab results, procedures, and prior admissions.
  • Evaluation: The authors used 5-fold cross-validation on a subset of 2,000 patients per fold, dealing with a naturally imbalanced task where only ~12% of patients were readmitted.

Key Insights and Ideas

  • Symbolic Interpretability: Unlike "black-box" neural networks, QDT is fully auditable. A clinician can look at the generated SQL to see exactly which features the model prioritized and what cohort it used for comparison.
  • Zero-Imputation Robustness: Missing data is a chronic issue in EHRs. QDT handles this naturally: if a feature is missing in the test record, the LLM simply omits that filter from its SQL WHERE clause. There is no need for synthetic data imputation.
  • Reasoning over Statistics: The "aha moment" is that LLMs are surprisingly good at acting as statisticians. By looking at the outcomes of 300 similar patients, the model can weigh the evidence to make a nuanced prediction for the individual at hand.
  • No Model Updates Required: Because the "knowledge" resides in the database and the "reasoning" in the LLM, the system scales to new tasks or updated data without any retraining or parameter tuning.

Key Results

Despite never accessing raw data, QDT outperformed established baselines in the diabetes readmission task:

Table 1: Performance comparison of different models on 30-day readmission prediction for Type 2 Diabetes patients predicted for a subset of 2,000 patients. Evaluation metrics include Precision, Recall, and F1-score. The errors are rep- resented as standard deviations (±). Query, Don’t Train (QDT) refers to using SQL queries to perform predictions without direct access to patient-level data.
  • Performance: QDT achieved an F1-score of 0.70, surpassing TabPFN (0.69) and XGBoost (0.66).
  • Ablation Study: The system proved remarkably robust to missing data. Even when 30% of features were removed from the test records, the F1-score only dropped slightly to 0.67. Even at 70% missingness, it maintained an F1 of 0.64, demonstrating the power of dynamic query planning.

Limitations and Future Work

  • Computational Overhead: Generating and executing multiple SQL queries per prediction is significantly slower than a single forward pass of a standard neural network.
  • Privacy Nuances: While the "k-anonymity" (aggregates of 2+) approach is a strong start, it is theoretically vulnerable to "differencing attacks" (inferring an individual's data by comparing two slightly different aggregate queries). The authors suggest integrating Differential Privacy in future iterations for stronger guarantees.
  • Data Modality: The current work is limited to structured tabular data. Extending this to multi-modal EHRs—incorporating medical images or unstructured clinical notes—remains a challenge for future prompt engineering and system design.

Summary updated

Abstract

Electronic health records (EHRs) contain richly structured, longitudinal data essential for predictive modeling, yet stringent privacy regulations (e.g., HIPAA, GDPR) often restrict access to individual-level records. We introduce \textbf{Query, Don't Train} (QDT): a \textbf{structured-data foundation-model interface} enabling \textbf{tabular inference} via LLM-generated SQL over EHRs. Instead of training on or accessing individual-level examples, QDT uses a large language model (LLM) as a schema-aware query planner to generate privacy-compliant SQL queries from a natural language task description and a test-time input. The model then extracts summary-level population statistics through these SQL queries, and the LLM performs chain-of-thought reasoning over the results to make predictions. This inference-time-only approach enables prediction without supervised model training, ensures interpretability through symbolic, auditable queries, naturally handles missing features without imputation or preprocessing, and effectively manages high-dimensional numerical data to enhance analytical capabilities. We validate QDT on the task of 30-day hospital readmission prediction for Type 2 diabetes patients using a MIMIC-style EHR cohort, achieving F1 = 0.70, which outperforms TabPFN (F1 = 0.68). To our knowledge, this is the first demonstration of LLM-driven, privacy-preserving structured prediction using only schema metadata and aggregate statistics -- offering a scalable, interpretable, and regulation-compliant alternative to conventional foundation-model pipelines.
BibTeX
@misc{stoisser2025query,
  author = {Josefa Lia Stoisser and Marc Boubnovski Martell and Kaspar Märtens and Lawrence Phillips and Stephen Michael Town and Rory Donovan-Maiye and Julien Fauqueur},
  title = {{Query, Don't Train: Privacy-Preserving Tabular Prediction from EHR Data via SQL Queries}},
  year = {2025},
  eprint = {2505.21801},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.21801},
}
Figure