[Paper Review] CBR-to-SQL: Rethinking Retrieval-based Text-to-SQL using Case-based Reasoning in the Healthcare Domain
CBR-to-SQL introduces a two-stage retrieval framework that uses masked case templates and a separate entity grounding step to translate natural language questions into SQL in healthcare, achieving state-of-the-art logical form accuracy and robust generalization, especially under data scarcity.
Extracting insights from Electronic Health Record (EHR) databases often requires SQL expertise, creating a barrier for healthcare decision-making and research. While a promising approach is to use Large Language Models (LLMs) to translate natural language questions to SQL via Retrieval-Augmented Generation (RAG), adapting this approach to the medical domain is non-trivial. Standard RAG relies on single-step retrieval from a static pool of examples, which struggles with the variability and noise of medical terminology and jargon. This often leads to anti-patterns such as expanding the task demonstration pool to improve coverage, which in turn introduces noise and scalability problems. To address this, we introduce CBR-to-SQL, a framework inspired by Case-Based Reasoning (CBR). It represents question-SQL pairs as reusable, abstract case templates and utilizes a two-stage retrieval process that first captures logical structure and then resolves relevant entities. Evaluated on MIMICSQL, CBR-to-SQL achieves state-of-the-art logical form accuracy and competitive execution accuracy. More importantly, it demonstrates higher sample efficiency and robustness than standard RAG approaches, particularly under data scarcity and retrieval perturbations.
Motivation & Objective
- Motivate text-to-SQL in the healthcare domain where SQL expertise is a barrier for EHR data access.
- Propose a Case-based Reasoning (CBR) framework that decouples logical structure retrieval from entity grounding.
- Show that masked case templates enable reusable patterns and improve sample efficiency and robustness.
Proposed method
- Convert question-SQL pairs into abstract case templates by masking schema-specific entities (Case Retain).
- During inference, retrieve similar masked templates (Template Construction) and generate a draft SQL template with an LLM.
- Ground placeholder entities against a schema-aware lookup table (Source Discovery) and fill in concrete schema entities to produce executable SQL.
- Use a two-stage retrieval approach to separate logical structure from entity resolution, leveraging separate data sources for patterns and EHR grounding.
- Evaluate on MIMICSQL with Complete and Incomplete Database settings, plus brittleness metrics to assess sensitivity to retrieved cases.

Experimental results
Research questions
- RQ1How does a two-stage, case-based retrieval framework perform compared to standard RAG in text-to-SQL for healthcare?
- RQ2Does masking and templating improve sample efficiency and robustness under data scarcity and retrieval perturbations?
- RQ3What is the impact of decoupling logical structure retrieval from entity grounding on accuracy and brittleness?
- RQ4How does CBR-to-SQL generalize to incomplete data regimes compared to RAG-based baselines?
Key findings
- CBR-to-SQL achieves higher Acc_EX and higher Acc_LF than RAG-to-SQL in the Complete Database setup (0.882 vs 0.855 for Acc_EX; 0.828 vs 0.811 for Acc_LF).
- CBR-to-SQL attains state-of-the-art Acc_LF and competitive Acc_EX on MIMICSQL, outperforming several baselines (e.g., TREQS, Coarse2Fine, PtrGen, SQLNet).
- In the Incomplete Database setup, CBR-to-SQL maintains a strong lead over RAG-to-SQL (0.842 vs 0.777 Acc_EX; 0.780 vs 0.747 Acc_LF).
- CBR-to-SQL shows lower brittleness than RAG-to-SQL under both Ex and LF metrics in both Complete and Incomplete settings (e.g., Δbrittle_EX: 0.047 vs 0.065 in CDB; Δbrittle_EX in IDB: 0.049 vs 0.068).
- Ablation studies reveal that removing Source Discovery drastically reduces performance, while masking-based Template Construction provides resilience against noise.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.