FD-NL2SQL: Feedback-Driven Clinical NL2SQL that Improves with Use

Suparno Roy Chowdhury, Tejas Anvekar, Manan Roy Choudhury, Muhammad Ali Khan, Kaneez Zahra Rubab Khakwani, Mohamad Bassam Sonbol, Irbaz Bin Riaz, Vivek Gupta

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:

  1. Schema Grounding: The system introspects the database to build a schema dictionary, ensuring the LLM remains constrained to valid tables and columns.
  2. 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?").
  3. 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.
  4. Retrieval-Guided Synthesis: A second LLM synthesizes the final executable SQL query, using the retrieved exemplars as structural templates while avoiding literal copying.
  5. Continuous Self-Evolution: The system improves with use via two feedback loops:
  6. Expert Approval: Clinicians can interactively edit and approve queries via a chat interface, saving corrected pairs directly back to the exemplar bank.
  7. 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.
FD-NL2SQL Architecture Pipeline

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.
Quantitative Results Table

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

Abstract

Clinicians exploring oncology trial repositories often need ad-hoc, multi-constraint queries over biomarkers, endpoints, interventions, and time, yet writing SQL requires schema expertise. We demo FD-NL2SQL, a feedback-driven clinical NL2SQL assistant for SQLite-based oncology databases. Given a natural-language question, a schema-aware LLM decomposes it into predicate-level sub-questions, retrieves semantically similar expert-verified NL2SQL exemplars via sentence embeddings, and synthesizes executable SQL conditioned on the decomposition, retrieved exemplars, and schema, with post-processing validity checks. To improve with use, FD-NL2SQL incorporates two update signals: (i) clinician edits of generated SQL are approved and added to the exemplar bank; and (ii) lightweight logic-based SQL augmentation applies a single atomic mutation (e.g., operator or column change), retaining variants only if they return non-empty results. A second LLM generates the corresponding natural-language question and predicate decomposition for accepted variants, automatically expanding the exemplar bank without additional annotation. The demo interface exposes decomposition, retrieval, synthesis, and execution results to support interactive refinement and continuous improvement.
BibTeX
@inproceedings{chowdhury2026fd,
  author = {Suparno Roy Chowdhury and Tejas Anvekar and Manan Roy Choudhury and Muhammad Ali Khan and Kaneez Zahra Rubab Khakwani and Mohamad Bassam Sonbol and Irbaz Bin Riaz and Vivek Gupta},
  title = {{FD-NL2SQL: Feedback-Driven Clinical NL2SQL that Improves with Use}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-demo.75},
}

Loading related content...

Figure