CBR-to-SQL: Rethinking Retrieval-based Text-to-SQL using Case-based Reasoning in the Healthcare Domain
Hung Nguyen, Hans Moen, Pekka Marttinen · 2026
Read CBR-to-SQL: Rethinking Retrieval-based Text-to-SQL using Case-based Reasoning in the Healthcare Domain by Hung Nguyen, Hans Moen, Pekka Marttinen (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2603-05569.txt.
Introduction
Nguyen and team offer CBR-to-SQL, a case-based reasoning framework splitting retrieval-boosted text-to-SQL making into two clear stages. Standard single-step retrieval struggles to tune logical structure and named items at once, often relying on near-exact matches. One stage finds examples that fit by structure, while the other aligns items with the target database schema. On two clinic benchmarks, the framework matches fine-tuned methods for rightness with much better use of samples and toughness, above all under data shortage and retrieval noise.
Catalog record
| CREATOR | Hung Nguyen, Hans Moen, Pekka Marttinen |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 55316 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2603.05569
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
CBR-to-SQL: Rethinking Retrieval-based Text-to-SQL using Case-based Reasoning in the Healthcare Domain Hung Nguyen, Hans Moen, Pekka Marttinen Abstract 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. keywords Case-based Reasoning, Text-to-SQL, Electronic Health Records, Retrieval-Augmented Generation, Large Language Model Data and Code Availability We use two datasets in this work: MIMICSQL ( 32 ) , a publicly available question–SQL dataset, and MIMIC-III ( 8 ) , the underlying EHR database. Code and results are available on GitHub (anonymized for submission). Institutional Review Board (IRB) This research does not require IRB approval. 1 Introduction Electronic Health Record (EHR) databases collect large volumes of patient data daily, including demographics, medical conditions, and diagnoses, which are critical for clinical decision-making and research. However, extracting insights from these databases is challenging for non-technical users, as it requires expertise in SQL and knowledge of database schemas ( 38 ) . Traditional interfaces rely on rigid, rule-based mappings that fall short in addressing the variability of real-world queries. A promising solution is to use Large Language Models (LLMs) for text-to-SQL translation, converting natural language (NL) questions into executable SQL, allowing users to focus on the information they are seeking rather than the technical details. While generalist LLMs have already demonstrated strong performance on open-domain text-to-SQL benchmarks, they struggle in specialized settings due to a lack of contextual grounding ( 7 ) . Fine-tuning can improve domain adaptation but is costly, complex, and unsuitable for dynamic environments ( 30 ) . Retrieval-Augmented Generation (RAG) ( 10 ) has emerged as a promising alternative, using an external knowledge base of question-SQL pairs to provide the LLM with contextual demonstrations at inference time, allowing effective generalization from few-shot learning without parameter updates. Although RAG has been extensively studied in open-domain text-to-SQL ( 17 ) , its adaptation to specialized domains like healthcare remains limited. This is largely due to the challenge of aligning noisy, variable medical jargon and even typos in human questions ( 32 ) . For standard RAG strategies to be effective, they must retrieve examples that align with not only the logical structure of the query but also the entities referenced in the NL question. However, most RAG-based designs rely on static, narrowly scoped task demonstrations that are noisy ( 31 ) , and their single-step retrieval mechanism requires near-exact matches to generalize effectively. One common workaround is to expand the demonstration pool to improve example diversity ( 13 ) , but this introduces noise, redundancy, and computational overhead, ultimately limiting generalization and scalability. To address these limitations, we formulate text-to-SQL as a Case-based Reasoning (CBR) problem ( 23 ) . Building on this formulation, we propose CBR-to-SQL , a retrieval-based framework inspired by the classical CBR cycle ( A ) that operates in two phases. In the offline Case Retain phase, we construct reusable case templates from question-SQL pairs by masking schema-specific details to expose the underlying problem pattern. During online inference, a two-step retrieval process leverages these cases: the Template Construction step retrieves relevant templates to reuse their logical structures and propose a draft SQL query, which the following Source Discovery step revises to adapt to entities mentioned in the NL question. Even though CBR-to-SQL shares certain technical features with 37 , namely in using a similar two-step retrieval process, our key novelty lies in the problem conceptualization. While the prior approach focuses on the specific problem of mapping medical terminology within a standard RAG framework, we argue that this issue reflects a deeper architectural limitation: single-step retrieval cannot simultaneously optimize logical structure alignment and entity mapping. By using a CBR framework that explicitly separates these aspects into clear, principled stages, we aim to address the broader problems of scalability and generalization that standard RAG faces in the medical domain. Overall, our main contributions are threefold. (1) We propose a novel CBR formulation for medical text-to-SQL that uses masked case templates instead of static question-SQL examples to improve generalization and scalability. (2) We present CBR-to-SQL , a framework that decomposes retrieval into individual stages that optimize a focused subproblem, logical structure retrieval and entity retrieval. We empirically demonstrate that this separation enhances sample efficiency, interpretability, and robustness using the MIMICSQL benchmark. (3) We propose a more challenging evaluation setup for generalization robustness of retrieval-based text-to-SQL models, including an Incomplete Database setting to evaluate performance under limited knowledge availability, and a brittleness metric to quantify sensitivity to retrieved examples. 2 Related Work Traditional text-to-SQL methods primarily rely on training specialized neural network architectures from scratch. They focus on addressing primitive challenges such as ensuring basic SQL syntax (the order-matter problem) using reinforcement learning ( 36 ) or syntax-aware decoding ( 28 ; 33 ) . In the medical domain, research focuses on introducing mechanisms to handle domain-specific and ambiguous medical terminology, such as attentive copying to align entity references in the output SQL with the schema ( 32 ) , or encoder-as-decoder architectures to attend to entities from input questions during decoding ( 2 ) . Recent research has increasingly favored utilizing the pre-trained capabilities of LLMs for text-to-SQL tasks via transfer learning methods. With their strong natural language understanding, LLMs can be adapted to complex domains such as healthcare with simple fine-tuning ( 14 ) . Since many LLMs in this area were at an early stage and often lack pre-training on coding tasks, many studies also focus on developing specialized decoding modules for LLMs during fine-tuning to enhance SQL syntactic correctness ( 24 ; 20 ) . As modern LLMs become more capable from pretraining on coding tasks, they can be adapted to text-to-SQL using prompt-based approaches such as RAG. Research in this field follows two parallel tracks: one is model-centric , focusing on developing more advanced context retrieval strategies ( 6 ; 26 ) , the other is data-centric , aiming to enhance context representation through techniques like knowledge graphs ( 25 ; 11 ) . In the medical domain, however, retrieval-based models remain relatively unexplored. A notable exception is the work of 38 , which tackles specialized medical terminology using masked retrieval and standardized medical codes to normalize entity references. 3 Method Figure 1: Overview of the CBR-to-SQL architecture. As illustrated in fig:system-architecture, CBR-to-SQL’s architecture includes three core components. The