TL;DR
Large language models can translate clinical questions into database queries (SQL), but doctors who don't read SQL have no way to verify if a generated query actually makes medical sense. This paper introduces VGSG-CoT, a framework that trains compact models to explain their SQL generation step-by-step in plain English while anchoring every decision in actual database values. By feeding the model explicit clues straight from the database, the authors overcome the accuracy drop usually seen when small models try to "think out loud," achieving state-of-the-art clinical query accuracy alongside an auditable reasoning trail.
What Problem Does This Paper Address?
Electronic medical records (EMRs) hold a treasure trove of patient data locked inside relational databases. Querying them requires SQL—a language few clinicians speak. Text-to-SQL models bridge this gap, but in medicine, a black-box query is dangerous: a slightly wrong query might still return a plausible-looking number, quietly misleading a clinical decision.
Unlike standard benchmarks full of complex nested logic, medical queries are structurally shallow (simple joins and counts) yet semantically dense. Clinical databases are a minefield of abbreviations, typos, and overlapping columns. For instance, an ICD-9 code like 5771 might refer to chronic pancreatitis in a diagnoses table or a radical cystectomy in a procedures table, and a phrase like "crnry athrscl natve vssl" has to be mapped to an exact string in a specific title column.
Clinicians need an auditable Chain-of-Thought (CoT) interface so they can inspect which tables, columns, and values the model chose without reading raw code. The catch? Forcing compact, hospital-deployable models (like 1.5B-parameter LLMs) to generate explicit reasoning steps actually hurts their SQL accuracy.
Methods
To get both high accuracy and faithful explanations in small models, the authors propose VGSG-CoT (Value-Grounded Schema-Graph Chain-of-Thought), built around three core ideas:
- Semantic-Operator CoT: Instead of breaking a query into complex sub-queries, each reasoning step represents a single "grounding decision"—selecting a table, identifying a column, grounding a literal value, joining tables, or aggregating. Each step pairs a plain-language explanation with a small witness SQL fragment, making consistency between the explanation and final query mathematically verifiable.
- Grounded Evidence Module (GEM): A parameter-free, deterministic lookup tool that scans the database before the model generates anything. It uses exact and fuzzy matching (character trigrams and edit distance) to link phrases in the user's question to actual stored cell values and column names, injecting these concrete clues directly into the prompt. Post-generation, it also normalizes slightly misspelled string literals back to their exact database spellings.
- Evidence-Grounded CoT Distillation: To create high-quality training data, a large teacher model (DeepSeek-V4-Flash) proposes reasoning steps, while a Monte Carlo Tree Search (MCTS) guided by Abstract Syntax Trees (ASTs) verifies that each step steadily builds toward the ground-truth SQL. Compact student models (Qwen2.5-Coder 1.5B and 7B) are then fine-tuned on these verified trajectories using a curriculum (easy queries first, oversampled hard queries later) and a token-weighted loss that weights final SQL tokens twice as heavily as CoT tokens.
Datasets
No new datasets are introduced, though the authors synthesize 8,234 verified CoT training trajectories. They evaluate on two existing benchmarks:
- MIMICSQL: The target EMR benchmark derived from the MIMIC-III critical care database (10,000 question–SQL pairs across 5 tables). Every single query filters on a literal value, and 22.5% of questions use surface forms (abbreviations, typos) that don't match the stored database text verbatim.
- Spider: A classic cross-domain benchmark (11,840 questions across 206 databases) featuring complex SQL structures, used here via LoRA adaptation to test whether the framework generalizes beyond medicine.
Key Insights and Ideas
- "Thinking out loud" taxes small models—unless they have an open book: Fine-tuning a 1.5B model on SQL alone yielded 90.7% accuracy, but adding CoT dropped it to 87.0%. Nearly all the new errors were bad table, column, or value guesses. Adding GEM's database evidence jumped accuracy to 94.3%—proving that grounding removes the guesswork that derails small reasoning models.
- Auditability shines brightest when the model fails: When VGSG-CoT gets a query wrong—such as picking the diagnosis meaning of an ambiguous ICD-9 code instead of the procedure meaning—its CoT remains 100% consistent with its SQL. It plainly states in English, "Join DEMOGRAPHIC to DIAGNOSES...", allowing a clinician to spot the clinical misunderstanding immediately without parsing SQL syntax.
Key Results
- Clinical Accuracy: On MIMICSQL, VGSG-CoT reaches 0.943 execution accuracy with the 1.5B model and 0.956 with the 7B model. Notably, the tiny 1.5B model beats a prior 8B graph-injected LLM (0.942) using less than a fifth of the parameters.
- Explanation Reliability: On MIMICSQL, CoT traceability is 100% (every element in the final SQL was explicitly declared in a reasoning step), step coverage exceeds 99.95%, and over 97% of value conditions cite real values stored in the database.
- Cross-Domain Transfer: On Spider, the 7B model achieves 0.712 execution accuracy (surpassing the 8B graph baseline at 0.696), while the 1.5B model reaches 0.510.
Limitations and Future Work
- Dependency on Literals: Because 46.1% of Spider questions contain no literal values (e.g., no specific names or titles to look up), GEM has much less database evidence to offer, causing the 1.5B model's accuracy to lag in general domains.
- Decoding Latency: Generating a structured CoT makes the output several times longer than emitting raw SQL alone, increasing inference time.
- Future Directions: The authors plan to tackle temporal clinical reasoning benchmarks (such as EHRSQL, which involves complex time-based questions) and explore privacy-preserving hospital deployments.
Summary updated