Memo-SQL: Structured Decomposition and Experience-Driven Self-Correction for Training-Free NL2SQL
Zerui Yang, Weichuan Wang, Yanwei Xu, Linqi Song, Yudai Matsuda, Wei Han, Bo Bai · 2026
Read Memo-SQL: Structured Decomposition and Experience-Driven Self-Correction for Training-Free NL2SQL by Zerui Yang, Weichuan Wang, Yanwei Xu, Linqi Song, Yudai Matsuda, Wei Han, Bo Bai (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-2601-10011.txt.
Introduction
Zerui Yang and co authors build a tool that turns plain words into code queries. The task is named NL2SQL. A user asks a fact in plain words. The tool must write a query that pulls the right rows. Past tools learn from right cases only.
That leaves a rich source untapped. Past wrong tries and their fixes show where tools fail. The team built Memo-SQL to use those pairs. It splits a hard ask into parts. It also fixes its own tries based on past fixes. The plan needs no fresh training. It learns from saved tries at test time.
Catalog record
| CREATOR | Zerui Yang, Weichuan Wang, Yanwei Xu, Linqi Song, Yudai Matsuda, Wei Han, Bo Bai |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 52 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2601-10011
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Memo-SQL: Structured Decomposition and Experience-Driven Self-Correction for Training-Free NL2SQL Zerui Yang, Weichuan Wang, Yanwei Xu, Linqi Song, Yudai Matsuda, Wei Han, Bo Bai Abstract Existing NL2SQL systems face two critical limitations : (1) they rely on in-context learning with only correct examples, overlooking the rich signal in historical error–fix pairs that could guide more robust self-correction; and (2) test-time scaling (TTS) approaches often decompose questions arbitrarily, producing near-identical SQL candidates across runs and diminishing ensemble gains. Moreover, these methods suffer from a stark accuracy–efficiency trade-off: high performance demands excessive computation, while fast variants compromise quality. We present Memo-SQL, a training-free framework that addresses these issues through two simple ideas: structured decomposition and experience-aware self-correction. Instead of leaving decomposition to chance, we apply three clear strategies, entity-wise, hierarchical, and atomic sequential, to encourage diverse reasoning. For correction, we build a dynamic memory of both successful queries and historical error–fix pairs, and use retrieval-augmented prompting to bring relevant examples into context at inference time, no fine-tuning or external APIs required. On BIRD, Memo-SQL achieves 68.5% execution accuracy, setting a new state of the art among open, zero-fine-tuning methods, while using over 10× fewer resources than prior TTS approaches. Contact : [email protected] 1 Introduction Recent progress in NL2SQL has been heavily reliant on either fine-tuning large language models (LLMs) 29 ; 16 or invoking powerful but closed-source APIs 25 ; 22 . While these approaches achieve strong performance on standard benchmarks, they suffer from clear drawbacks, most notably, an inability to incorporate dynamic feedback and poor generalization beyond static training setups. This has spurred growing interest in TTS 7 ; 38 , a paradigm that enhances inference-time computation without modifying model parameters, thereby enabling fully open, training-free solutions based on publicly available LLMs. Despite its promise, current TTS methods 40 ; 12 for NL2SQL still suffer from several fundamental limitations that hinder both effectiveness and practicality. Figure 1: Conceptual comparison between a standard user-in-the-loop NL2SQL workflow and our proposed self-correction framework. In the standard approach, the model generates an initial SQL query, which is then revised through explicit user feedback, a process that typically stores only correct examples in the experience repository. In contrast, our framework introduces an automatic self-correction step after generation: it retrieves relevant error–correction pairs from a dynamic error-correction memory (including past failures) and refines the output without requiring user intervention, enabling fully training-free adaptation. First, they often struggle to balance accuracy and efficiency, with high-performing systems incurring prohibitive computational costs 29 ; 15 . Second, many divide-and-conquer frameworks delegate the entire question decomposition process to the LLM itself 35 ; 25 . While seemingly flexible, this approach often produces highly similar or even identical sub-question sequences across different runs 20 . The resulting SQL candidates are strongly correlated, which severely limits the utility of ensemble techniques like majority voting, precisely because meaningful diversity in reasoning paths is absent. Although some recent works combine divide-and-conquer with external planning modules or tool-augmented reasoning 25 ; 13 , our focus lies squarely on improving the core decomposition mechanism itself, without relying on auxiliary components, to unlock its full potential under a pure test-time scaling setting. Third, existing self-correction mechanisms typically rely on static few-shot prompts that embed fixed examples of error-fix patterns 26 ; 37 . These static demonstrations primarily serve to familiarize the model with the task format rather than genuinely enhancing its ability to diagnose and correct novel errors. Consequently, such designs cannot adapt to novel error types, evolving query formulations, or domain-specific schema quirks, often resulting in ineffective self-correction or requiring users to provide multiple rounds of clarification 8 ; 1 ; 41 . Moreover, they treat all past interactions as transient, discarding valuable feedback from user corrections, a rich source of supervision that could guide more robust and generalizable refinement. To address these challenges, we propose Memo-SQL, a training-free TTS framework that operates exclusively with open-source LLMs and requires no external APIs or parameter updates. Memo-SQL delivers three key contributions: (1) A principled divide-and-conquer framework for NL2SQL. Rather than leaving decomposition to the stochastic discretion of the LLM, an approach that often collapses into repetitive reasoning patterns, we formalize SQL generation as a structured divide-and-conquer process. Our framework explicitly decomposes natural language questions along multiple semantic axes (e.g., entity relations, query nesting, and operational sequencing), ensuring broad coverage of compositional structures and promoting diversity in the resulting candidate programs. (2) Experience-guided self-correction via error-aware in-context learning. While retrieval-augmented in-context learning has been used to retrieve successful demonstrations 18 ; 32 , we repurpose this mechanism for learning from failures. Specifically, we retrieve historical error-correction pairs, not just correct queries, and inject them as dynamic in-context examples during self-correction. This allows the model to explicitly reason about common failure modes and their fixes, enabling adaptive refinement that generalizes across error types and domains, without fine-tuning or handcrafted rules. (3) State-of-the-art performance with high efficiency. Evaluated on the BIRD benchmark ( 17 ) , Memo-SQL achieves 68.5% execution accuracy on the dev-new set, setting a new state of the art among all open, zero-fine-tuning methods. Remarkably, it reduces computational overhead by over an order of magnitude compared to leading TTS approaches, demonstrating that principled test-time reasoning can simultaneously achieve high accuracy, strong adaptability, and low latency. Figure 2: Overview of the Memo-SQL framework, which integrates problem decomposition, ReAct+Reflection reasoning, and self-correction to generate accurate SQL queries. The pipeline begins with preprocessing and multi-strategy question decomposition. Each sub-problem is solved via an iterative ReAct+Reflection loop: (1) reasoning about semantics, (2) generating a sub-SQL query, (3) observing execution results, and (4) reflecting on potential errors to enable one-step correction. Finally, multiple SQL candidates are synthesized using few-shot in-context learning across three syntactic styles (CTE, flat JOIN, nested), followed by error-aware refinement, guided by a error-correction memory, and selection via self-consistency scoring. 2 Preliminary 2.1 Divide-and-Conquer for NL2SQL Given a natural language question q and a database schema \mathcal{S} , the goal of NL2SQL is to generate an executable SQL query y . In divide-and-conquer approaches, x is first decomposed into a sequence of sub-questions \{x_{1},x_{2},\dots,x_{k}\} , each targeting a specific aspect of \mathcal{S} (e.g., entities, joins, or aggregations). The corresponding SQL fragments \{y_{1},\dots,y_{k}\} are then composed into the final query: \begin{split}y&=\texttt{Compose}(y_{1},y_{2},\dots,y_{k}),\\ &\quad\text{where }y_{i}=\texttt{Gen}(x_{i};\theta).\end{split} (1) When decomposition is left entirely to the LLM (i.e., \{x_{i}\} are sampled stochastically), the resulting \{y_{i}\} often exhibit low structural diversity 20 , limiting ensemble robustness. 2.2 In-Context Learning for Self-Correction Current self-correction methods use static in-context learning 26 ; 37 . A fixed set of error–correction demonstrations \mathcal{D}_{\text{static}}=\{(y^{\text{err}}_{j},y^{\text{corr}}_{j})\}_{j=1}^{m} is embedded into the prompt: p_{\text{prompt}}=[\mathcal{D}_{\text{static}};\,y^{\text{err}}_{\text{new}}], (2) and the model generates a corrected version y^{\text{corr}}_{\text{new}}=\texttt{LLM}(p_{\text{prompt}}) . Since \mathcal{D}_{\text{static}} is handcrafted and static, it cannot adapt to unseen error patterns or domain shifts. 2.3 Experience-Aware Self-Correction via Retrieval-Augmented ICL As outlined in Section A.1 and Figure 1 , real-world BI systems log both user feedback and system revisions, forming a rich repository of error–correction experiences. Inspired by this practice, we maintain a dynamic experience repository \mathcal{M}=\{(x^{(i)},y^{\text{err}}_{(i)},y^{\text{corr}}_{(i)})\}_{i=1}^{N} . During inference, given a newly generated (possibly incorrect) query y^{\text{err}} , we retrieve the top- k most relevant error–correction pairs using a retriever \mathcal{R} : \mathcal{D}_{\text{retrieved}}=\mathcal{R}(y^{\text{err}};\mathcal{M})=\mathop{\mathrm{arg\,top\text{-}k}}_{(y^{\text{err}}_{(i)},y^{\text{corr}}_{(i)})\in\mathcal{M}}\text{sim}(y^{\text{err}},y^{\text{err}}_{(i)}), (3) where \text{sim}(\cdot,\cdot) is a similarity function