TL;DR
FD-NL2SQL is a feedback-driven text-to-SQL assistant designed to help clinicians query complex oncology clinical trial databases without needing database expertise. By decomposing natural language into atomic predicates and leveraging a self-evolving bank of expert-verified exemplars, the system significantly improves query accuracy and continuously adapts to user behavior over time.
What Problem Does This Paper Address?
Clinicians and translational researchers frequently need to explore clinical trial registries (such as ClinicalTrials.gov) to find patient cohorts, analyze endpoints, or track specific biomarkers. However, these registries rely on complex, multi-table relational databases. Querying them requires precise SQL expertise and deep familiarity with domain-specific schemas.
While general-purpose Large Language Models (LLMs) have made massive strides in Text-to-SQL tasks, they remain brittle when applied to highly specialized medical fields. Naive LLM generation often drops critical constraints, hallucinates column names, or generates clinically implausible queries. Traditional alternatives like keyword searches or rigid dashboards fail to support the complex, multi-constraint queries that precision oncology demands.
Methods
The authors introduce FD-NL2SQL, a modular framework that bridges the gap between natural language and structured clinical data through a multi-step pipeline:
- Schema Grounding: The system introspects the database to build a schema dictionary, ensuring the LLM remains constrained to valid tables and columns.
- Predicate Decomposition: Instead of translating the entire question at once, a schema-aware LLM breaks the user's query down into atomic,
WHERE-clause-oriented sub-questions (e.g., translating "began in 2018 or later" into "Which trials have Year >= 2018?"). - Exemplar Retrieval: Using Sentence-BERT embeddings, the system retrieves the top-$k$ most semantically similar, expert-approved query templates from an exemplar bank for each sub-question.
- Retrieval-Guided Synthesis: A second LLM synthesizes the final executable SQL query, using the retrieved exemplars as structural templates while avoiding literal copying.
- Continuous Self-Evolution: The system improves with use via two feedback loops:
- Expert Approval: Clinicians can interactively edit and approve queries via a chat interface, saving corrected pairs directly back to the exemplar bank.
- Logic-Based SQL Augmentation: To expand coverage automatically, the system applies atomic mutations (e.g., swapping operators or columns) to approved queries. If the mutated query executes successfully and returns a non-empty result, an LLM back-translates it into a natural language question to expand the exemplar bank without manual annotation.
Datasets
- Seed Set: 500 realistic clinical evidence-review questions authored by an oncology scientist at the Mayo Clinic, paired with gold-standard SQLite queries over the IOTOX database.
- Programmatic Benchmark Expansion: 1,500 diverse NL2SQL samples generated via the system's automated mutation and back-translation pipeline, manually verified for correctness by the authors to stress-test model generalization.
Key Insights and Ideas
- Decomposition Prevents Omission: Breaking complex queries into predicate-level sub-questions ensures that the LLM satisfies all constraints, drastically reducing the omission of critical clinical filters.
- Chain-of-Thought (CoT) Can Backfire: Interestingly, standard CoT prompting actually degraded execution correctness for several models. The models frequently introduced noisy, incorrect intermediate assumptions that leaked into and corrupted the final SQL syntax.
- Narrows the Performance Gap: The retrieval-guided framework acts as an equalizer, allowing smaller, open-source models (like Qwen3 and Gemma3) to approach or match the reliability of massive, expensive proprietary models.
Key Results
The framework was evaluated across multiple state-of-the-art LLM backbones, consistently outperforming standard zero-shot, few-shot, and CoT baselines:
- Accuracy Boost: For the Qwen3 backbone, exact match execution accuracy (eEM) jumped from 26.90% in a zero-shot setting to 40.93% using FD-NL2SQL.
- High Structural Fidelity: The gpt-5-mini variant achieved an eEM of 39.20% and an Abstract Syntax Tree (AST) structural similarity score of 87.14, demonstrating highly reliable query formulation.
- Finetuned Models Fall Short: Reasoning-focused models like SQL-R1-14B struggled significantly (scoring as low as 3.32% eEM), proving that reinforcement learning alone cannot overcome severe domain and schema mismatches without explicit retrieval grounding.
Limitations and Future Work
- Simplified Mutations: The automated data augmentation pipeline relies on single, lightweight atomic edits. This might limit the system's ability to automatically learn and generate highly complex query patterns involving nested SQL or intricate table joins.
- Data Bias: Filtering out mutated queries that yield empty results ensures validity but may bias the exemplar bank toward common clinical conditions, potentially undersampling rare cancers or niche endpoints.
- Lack of Clinical Trial Deployment: The system has currently only been evaluated offline; prospective user studies and formal institutional privacy/security audits are required before real-world clinical deployment.
Summary updated