Causal Episodic Memory for Feedback-Driven Agent Repair

arXiv cs.CL 论文

摘要

This paper introduces MERIT, a training-free agent that uses causal episodic memory of past repair outcomes to improve subsequent Text-to-SQL generations, boosting execution accuracy on Spider and BIRD benchmarks.

arXiv:2608.05906v1 Announce Type: new Abstract: LLM agents that repair failures often discard successful corrections, forcing later episodes to rediscover similar solutions. We study whether finalized repair outcomes can improve subsequent Text-to-SQL episodes without parameter updates. We introduce MERIT, a training-free agent that maintains an online dual-polarity memory of oracle-verified corrections and observed unsuccessful directions. Under oracle-assisted benchmark feedback, only memories from earlier finalized episodes are eligible for retrieval. A deterministic classifier assigns a coarse failure type, which conditions a hybrid lexical-dense retriever before the frozen model generates each revision. Using Qwen2.5-7B-Instruct with identical initial predictions and repair budgets, MERIT improves execution accuracy over stateless iterative repair from \(66.34\%\) to \(69.79\%\) on Spider and from \(47.35\%\) to \(48.44\%\) on BIRD. Paired analyses provide clear evidence for the Spider gain but weaker evidence on BIRD. MERIT is not reliably separated from untyped dynamic retrieval on either benchmark, while Reflexion-style memory reaches \(51.24\%\) on BIRD at substantially higher inference cost. Ablations show that negative memory contributes modestly, the value of type conditioning and lexical--dense ranking is dataset dependent, and schema-local experience provides the most consistent benefit. These results clarify when causal cross-query memory improves repair and when broader memory representations remain preferable.
查看原文
查看缓存全文

缓存时间: 2026/08/07 07:52

# Causal Episodic Memory for Feedback-Driven Agent Repair
Source: [https://arxiv.org/html/2608.05906](https://arxiv.org/html/2608.05906)
Khang Nhat Hoang Vo1,Tam Minh Chu2,Anh Trac Duc Dinh2 Thuyen Vinh Ha Bui2,Tho Quan2 1Mohamed bin Zayed University of Artificial Intelligence, Abu Dhabi, United Arab Emirates 2Faculty of Computer Science and Engineering, Ho Chi Minh City University of Technology \(HCMUT\), VNU\-HCM, Ho Chi Minh City, Vietnam Correspondence:[Khang\.Vo@mbzuai\.ac\.ae](https://arxiv.org/html/2608.05906v1/mailto:[email protected]),[qttho@hcmut\.edu\.vn](https://arxiv.org/html/2608.05906v1/mailto:[email protected])

###### Abstract

LLM agents that repair failures often discard successful corrections, forcing later episodes to rediscover similar solutions\. We study whether finalized repair outcomes can improve subsequent Text\-to\-SQL episodes without parameter updates\. We introduce MERIT, a training\-free agent that maintains an online dual\-polarity memory of oracle\-verified corrections and observed unsuccessful directions\. Under oracle\-assisted benchmark feedback, only memories from earlier finalized episodes are eligible for retrieval\. A deterministic classifier assigns a coarse failure type, which conditions a hybrid lexical\-dense retriever before the frozen model generates each revision\. Using Qwen2\.5\-7B\-Instruct with identical initial predictions and repair budgets, MERIT improves execution accuracy over stateless iterative repair from66\.34%66\.34\\%to69\.79%69\.79\\%on Spider and from47\.35%47\.35\\%to48\.44%48\.44\\%on BIRD\. Paired analyses provide clear evidence for the Spider gain but weaker evidence on BIRD\. MERIT is not reliably separated from untyped dynamic retrieval on either benchmark, while Reflexion\-style memory reaches51\.24%51\.24\\%on BIRD at substantially higher inference cost\. Ablations show that negative memory contributes modestly, the value of type conditioning and lexical–dense ranking is dataset dependent, and schema\-local experience provides the most consistent benefit\. These results clarify when causal cross\-query memory improves repair and when broader memory representations remain preferable\.

Causal Episodic Memory for Feedback\-Driven Agent Repair

Khang Nhat Hoang Vo1, Tam Minh Chu2, Anh Trac Duc Dinh2Thuyen Vinh Ha Bui2,Tho Quan21Mohamed bin Zayed University of Artificial Intelligence, Abu Dhabi, United Arab Emirates2Faculty of Computer Science and Engineering, Ho Chi Minh City University of Technology\(HCMUT\), VNU\-HCM, Ho Chi Minh City, VietnamCorrespondence:[Khang\.Vo@mbzuai\.ac\.ae](https://arxiv.org/html/2608.05906v1/mailto:[email protected]),[qttho@hcmut\.edu\.vn](https://arxiv.org/html/2608.05906v1/mailto:[email protected])

## 1Introduction

Dependable language agents must do more than produce a correct action once: they must respond to environmental feedback and retain what they learn from it\. ReAct established the interleaving of reasoning, acting, and environment observations, while Self\-Refine, CRITIC, and Self\-Debugging showed that iterative feedback, external tools, and execution signals can improve an agent’s current outputYaoet al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib26)\); Madaanet al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib6)\); Gouet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib5)\); Chenet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib4)\)\. Such grounding is important because intrinsic self\-correction without external evidence is often unreliable and can even degrade reasoning performanceHuanget al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib27)\)\. In Text\-to\-SQL, decomposition and execution\-guided refinement have likewise improved generation by diagnosing or revising a query within its current episodePourreza and Rafiei \([2023](https://arxiv.org/html/2608.05906#bib.bib13)\); Daiet al\.\([2026](https://arxiv.org/html/2608.05906#bib.bib28)\)\. These methods, however, largely treat each new query as a fresh problem\. Once a useful correction has been discovered, it is typically unavailable when a similar failure appears in a later query\. This limits an agent’s ability to improve through continued interaction, even when failures such as missing joins, invalid schema references, and incorrect aggregations recur across tasks\.

Cross\-episode memory offers a mechanism for learning from such experience without modifying model parameters\. Reflexion retains verbal reflections from earlier trials, and ExpeL extracts reusable natural language knowledge from collections of agent trajectoriesShinnet al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib7)\); Zhaoet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib8)\)\. In Text\-to\-SQL, retrieval\-based methods such as DAIL\-SQL and ACT\-SQL instead select question\-SQL demonstrations to improve initial generationGaoet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib16)\); Zhanget al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib17)\)\. These approaches demonstrate the value of recalling prior experience, but they do not organize repair memories jointly by the failure that produced them and the outcome of the attempted correction\. Semantic similarity alone may therefore retrieve irrelevant episodes or conflate unsuccessful attempts with verified corrections\. We study whether structured episodic memory can improve cross\-query repair performance\.

We introduceMERIT\(Memory\-AugmentedError\-TypedRetrieval forIterativeText\-to\-SQL repair\), a training\-free agent that accumulates structured repair experience online\. MERIT stores oracle\-verified corrections as positive guidance and observed unsuccessful directions as negative guidance\. A deterministic classifier assigns a coarse failure type, which conditions a hybrid lexical–dense retriever before the frozen model generates each repair\. Only memories from finalized earlier episodes are available to the current query, enabling improvement through cross\-query experience without parameter updates\. We study this process under oracle\-assisted benchmark feedback\. Here,*causal*denotes temporal memory availability, not the absence of correctness supervision\. We make three contributions:

- •We introduce MERIT and formulate Text\-to\-SQL correction as*causal episodic memory for feedback\-driven agent repair*, in which only outcomes from finalized earlier episodes may guide the current query\.
- •We propose error\-guided hybrid retrieval that organizes repair experience by outcome and failure type, then ranks precedents using lexical and dense signals\.
- •We provide a controlled evaluation over three stream orders, comparing accuracy, repair behavior, and inference cost across MERIT and alternative cross\-query memory strategies\.

## 2Related Work

#### LLM\-based Text\-to\-SQL\.

Recent Text\-to\-SQL systems improve semantic parsing through structured reasoning, candidate generation, and in\-context example selection\. DIN\-SQL decomposes complex questions into schema linking, classification, and staged SQL generationPourreza and Rafiei \([2023](https://arxiv.org/html/2608.05906#bib.bib13)\); CHASE\-SQL explores multiple reasoning paths and selects candidates using execution\-guided signalsPourrezaet al\.\([2025](https://arxiv.org/html/2608.05906#bib.bib14)\); and SQL\-PaLM studies instruction tuning and prompting at larger model scalesSunet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib15)\)\. Retrieval\-based prompting provides another source of improvement: DAIL\-SQL selects demonstrations using question and SQL similarity, while ACT\-SQL retrieves examples augmented with automatically generated reasoning tracesGaoet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib16)\); Zhanget al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib17)\)\. These methods primarily target the quality of the initial prediction or select demonstrations from a pre\-constructed pool\. MERIT instead begins from a failed prediction and studies whether the correction discovered for one query can improve the repair of later queries\.

#### Execution\-guided correction\.

Environment feedback provides an external signal for revising generated programs and structured outputs\. Self\-Debugging uses execution results to diagnose and revise code, Self\-Refine iteratively improves outputs through model\-generated feedback, and CRITIC grounds correction in tool\-mediated critiqueChenet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib4)\); Madaanet al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib6)\); Gouet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib5)\)\. Related work has applied execution\-guided diagnosis and repair directly to SQLShenet al\.\([2026](https://arxiv.org/html/2608.05906#bib.bib1)\); Chau and Peters \([2025](https://arxiv.org/html/2608.05906#bib.bib2)\); Gonget al\.\([2025](https://arxiv.org/html/2608.05906#bib.bib3)\)\. More specialized Text\-to\-SQL agents introduce self\-correction guidelines, multi\-agent refinement, search over candidate rewrites, or difficulty\-aware question rewritingAskariet al\.\([2025](https://arxiv.org/html/2608.05906#bib.bib18)\); Denget al\.\([2025](https://arxiv.org/html/2608.05906#bib.bib19)\); Lyuet al\.\([2025](https://arxiv.org/html/2608.05906#bib.bib20)\); Maoet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib21)\)\. These approaches strengthen the correction process within a query\. MERIT addresses a complementary question: how that experience should be retained and reused after the current query ends\.

#### Experience retrieval and agent memory\.

Several agent architectures use memory to transfer information across episodes\. Reflexion converts feedback into verbal reflections that guide later trialsShinnet al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib7)\), while ExpeL extracts reusable knowledge from collections of successful and failed trajectoriesZhaoet al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib8)\)\. Retrieval\-augmented repair methods similarly expand an experience pool and retrieve related examples for subsequent problemsZhaoet al\.\([2025](https://arxiv.org/html/2608.05906#bib.bib9)\)\. General\-purpose memory systems address longer\-running interaction and recall: MemGPT manages information across working and archival memory, Generative Agents maintain experience streams and higher\-level reflections, and MemoryBank stores long\-term conversational experiencePackeret al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib22)\); Parket al\.\([2023](https://arxiv.org/html/2608.05906#bib.bib24)\); Zhonget al\.\([2024](https://arxiv.org/html/2608.05906#bib.bib25)\)\. Together, these works establish that agents can benefit from experience beyond the immediate context, but they do not prescribe how execution\-derived repair evidence should be represented\.

MERIT adapts cross\-episode memory to online Text\-to\-SQL repair by storing transformations discovered after an initial prediction fails, rather than demonstrations intended for first\-pass generation\. Its memory distinguishes execution\-verified corrections from selected unsuccessful directions and assigns each entry a coarse failure type\. This label acts as a retrieval prior, while lexical and dense similarity rank candidate precedents within the resulting pool\. The formulation therefore supports a controlled study of how polarity, failure typing, ranking, and schema locality shape the value of cross\-query repair experience\.

## 3Methodology

![Refer to caption](https://arxiv.org/html/2608.05906v1/x1.png)Figure 1:Overview of MERIT’s causal online repair process\. A frozen LLM produces a shared initial SQL prediction\. After an unsuccessful attempt, MERIT classifies the observed failure, retrieves experience from earlier finalized episodes, and generates one revision\. A benchmark correctness oracle controls termination and memory polarity without exposing the reference SQL or result rows to the model\. Current\-query attempts remain local, and each finalized episode contributes at most one memory entry that becomes visible only to later queries\.### 3\.1Causal Online Repair Formulation

Figure[1](https://arxiv.org/html/2608.05906#S3.F1)presents MERIT as an online correction–accumulation process\. At stream positiontt, the agent receives a questionqtq\_\{t\}, schemaStS\_\{t\}, optional dataset evidenceata\_\{t\}, executable databaseDtD\_\{t\}, and shared initial SQL predictionyt\(0\)y\_\{t\}^\{\(0\)\}\. The prediction is generated once with greedy decoding and reused by every repair method, isolating the effect of the repair strategy\.

#### Observable feedback and benchmark correctness\.

Our main experiments use thedenotation\_confirmedregime\. After attemptkk, the benchmark evaluator returnsV​\(Dt,yt\(k\)\)=\(zt\(k\),ϵt\(k\)\)V\(D\_\{t\},y\_\{t\}^\{\(k\)\}\)=\(z\_\{t\}^\{\(k\)\},\\epsilon\_\{t\}^\{\(k\)\}\), wherezt\(k\)z\_\{t\}^\{\(k\)\}isCorrect,Denotation Mismatch,Execution Error, orTimeout, andϵt\(k\)\\epsilon\_\{t\}^\{\(k\)\}contains the latest observable Database Management System \(DBMS\) error when one exists\. Spider uses the pinned test\-suite execution protocol, whereas BIRD compares predicted and reference result rows under the pinned timeout protocol\.

The reference SQL and reference rows remain isolated inside the evaluator and are not supplied to generation, classification, or retrieval\. The model receives only the attempt status, available DBMS error, and predicted failure type\. Nevertheless, the oracle decision controls episode termination and memory polarity\. The reported setting is therefore oracle\-assisted benchmark repair rather than autonomous correction from DBMS feedback alone\.

Each initially incorrect query defines one episode\. Afterkkrepair generations, its local history isHt\(k\)=\(yt\(0\),…,yt\(k\)\)H\_\{t\}^\{\(k\)\}=\(y\_\{t\}^\{\(0\)\},\\ldots,y\_\{t\}^\{\(k\)\}\), whileℳ<t\\mathcal\{M\}\_\{<t\}contains entries produced by finalized episodes at earlier stream positions\. Given a repair budgetK=7K=7, the objective is to find someyt\(k\)y\_\{t\}^\{\(k\)\},k≤Kk\\leq K, for whichzt\(k\)=Correctz\_\{t\}^\{\(k\)\}=\\textsc\{Correct\}\.

Current\-query attempts remain inHt\(k\)H\_\{t\}^\{\(k\)\}and cannot enter cross\-query retrieval\. A memory entryxxis eligible only ifsourcePos⁡\(x\)<t\\operatorname\{sourcePos\}\(x\)<tandsourceQuery⁡\(x\)≠qt\\operatorname\{sourceQuery\}\(x\)\\neq q\_\{t\}, and global memory is updated only after episode termination\. Thus,*causal*refers to temporal memory availability: the current query cannot access its unfinished trajectory or future\-query experience\.

### 3\.2MERIT: Correction and Experience Accumulation

MERIT combines a deterministic failure classifier, an online dual\-polarity memory, and a type\-conditioned hybrid retriever\. For each unsuccessful candidate, MERIT classifies the current failure, retrieves causally available experience, and prompts the frozen model to generate one revision\. The episode continues until oracle\-confirmed correctness or budget exhaustion\.

#### Initialization and failure diagnosis\.

Ifyt\(0\)y\_\{t\}^\{\(0\)\}is oracle\-confirmed correct, the query is finalized without creating repair memory because no corrective transition was observed\. Otherwise, MERIT initializesHt\(0\)=\[yt\(0\)\]H\_\{t\}^\{\(0\)\}=\[y\_\{t\}^\{\(0\)\}\]and enters the repair loop\.

At stepkk, the classifier maps the current unsuccessful queryyt\(k−1\)y\_\{t\}^\{\(k\-1\)\}to a failure typeτt\(k−1\)\\tau\_\{t\}^\{\(k\-1\)\}\. Its output categories areResult Mismatch,Schema Linking,Aggregation,Filter/Value,Execution,Syntax, andUnknown\. The classifier is deterministic and uses only execution status and observable DBMS text\. Ordered rules identify schema\-reference errors, parse failures, aggregate misuse, type mismatches, execution failures, and timeouts; the first matching rule determines the label\. Other nonempty DBMS errors map toUnknown, while executable but oracle\-incorrect SQL maps toResult Mismatch\. The classifier does not inspect the SQL AST or infer semantic errors such as incorrect joins or ordering\. The label is recomputed after each unsuccessful revision and serves only as a retrieval prior\. The complete rules appear in Appendix[C](https://arxiv.org/html/2608.05906#A3)\.

#### Online dual\-polarity memory\.

Memory is partitioned into positive and negative pools,ℳ<t=ℳ<t\+∪ℳ<t−\\mathcal\{M\}\_\{<t\}=\\mathcal\{M\}\_\{<t\}^\{\+\}\\cup\\mathcal\{M\}\_\{<t\}^\{\-\}\. An entry is represented asx=⟨c,τ,Δ,o,ρ⟩x=\\langle c,\\tau,\\Delta,o,\\rho\\rangle, whereccstores the source question, schema, unsuccessful SQL, status, and observable feedback;τ\\tauis the source failure type;Δ\\Deltadescribes the observed SQL transformation;o∈\{\+,−\}o\\in\\\{\+,\-\\\}is the polarity; andρ\\rhorecords provenance\.

A positive entry records an oracle\-confirmed failed\-to\-correct transitiony−→y\+y^\{\-\}\\rightarrow y^\{\+\}\. A negative entry records the final direction attempted in an unresolved episode, indicating only that it failed in its source context without asserting an unobserved cause or universal invalidity\.

#### Causal, type\-conditioned retrieval\.

Candidate construction is performed independently for polarityp∈\{\+,−\}p\\in\\\{\+,\-\\\}\. Letℒt,p⊆ℳ<tp\\mathcal\{L\}\_\{t,p\}\\subseteq\\mathcal\{M\}\_\{<t\}^\{p\}be the legal same\-polarity pool after applying the temporal, query, and database constraints\. Its same\-type subset is𝒯t,p=\{x∈ℒt,p:τx=τt\(k−1\)\}\\mathcal\{T\}\_\{t,p\}=\\\{x\\in\\mathcal\{L\}\_\{t,p\}:\\tau\_\{x\}=\\tau\_\{t\}^\{\(k\-1\)\}\\\}\. Full MERIT selects

𝒞t,p=\{𝒯t,p,\|𝒯t,p\|≥3,ℒt,p,otherwise\.\\mathcal\{C\}\_\{t,p\}=\\begin\{cases\}\\mathcal\{T\}\_\{t,p\},&\|\\mathcal\{T\}\_\{t,p\}\|\\geq 3,\\\\ \\mathcal\{L\}\_\{t,p\},&\\text\{otherwise\}\.\\end\{cases\}\(1\)
Thus, retrieval remains within the predicted type when at least three same\-type entries exist in that polarity; otherwise, it falls back to the complete legal same\-polarity pool\.

Dense and BM25 scores are independently min–max normalized within each selected polarity pool\. Letd^​\(x,u\)\\widehat\{d\}\(x,u\)andb^​\(x,u\)\\widehat\{b\}\(x,u\)denote the normalized dense and BM25 scores of candidatexxfor retrieval contextu=ut\(k\)u=u\_\{t\}^\{\(k\)\}\. Full MERIT ranks candidates byr​\(x,u\)=0\.75​d^​\(x,u\)\+0\.25​b^​\(x,u\)r\(x,u\)=0\.75\\,\\widehat\{d\}\(x,u\)\+0\.25\\,\\widehat\{b\}\(x,u\)\.

The retrieval query concatenates the current question, SQL, failure context, and error type\. Dense similarity captures semantic relatedness, whereas BM25 preserves exact overlap in question terms, schema identifiers, failure context, and SQL changes\. Positive and negative entries are ranked separately, and MERIT retrieves at most three positive and one negative entry\. Encoder, indexing, serialization, normalization, BM25, and tie\-breaking details are provided in Appendix[D](https://arxiv.org/html/2608.05906#A4)\.

#### Repair generation and validation\.

The repair prompt contains the question, schema, optional dataset evidence, current SQL, attempt status, DBMS error, predicted failure type, local history, and retrieved memories\. Positive entries are presented as confirmed successful directions, whereas negative entries are presented as observed unsuccessful directions\. The reference SQL, reference rows, and corrected query are never included\.

MERIT provides no separate system prompt: each template is sent as one user message through the model’s chat template\. MERIT Full does not generate local reflections\. The frozen model generates one revisionyt\(k\)=P​\(pt\(k\)\)y\_\{t\}^\{\(k\)\}=P\(p\_\{t\}^\{\(k\)\}\)using greedy decoding; complete prompts and memory serialization are given in Appendix[B](https://arxiv.org/html/2608.05906#A2)\.

The revision is appended to the local history and evaluated by the benchmark oracle\. If it is confirmed correct, the episode terminates\. Otherwise, MERIT reclassifies the resulting failure and repeats retrieval and generation while budget remains\.

#### Episode finalization and memory update\.

If repair succeeds at stepk∗k^\{\*\}, MERIT creates one positive entry from the final oracle\-confirmed transitionyt\(k∗−1\)→yt\(k∗\)y\_\{t\}^\{\(k^\{\*\}\-1\)\}\\rightarrow y\_\{t\}^\{\(k^\{\*\}\)\}\. Intermediate unsuccessful attempts remain local\. If no attempt is confirmed correct afterKKgenerations, MERIT creates at most one negative entry from the final observed directionyt\(K−1\)→yt\(K\)y\_\{t\}^\{\(K\-1\)\}\\rightarrow y\_\{t\}^\{\(K\)\}\.

Letxt∈\{xt\+,xt−,∅\}x\_\{t\}\\in\\\{x\_\{t\}^\{\+\},x\_\{t\}^\{\-\},\\varnothing\\\}denote the finalized outcome; memory is updated only upon finalization

ℳ<\(t\+1\)=ℳ<t∪\(\{xt\}∖\{∅\}\)\\mathcal\{M\}\_\{<\(t\+1\)\}=\\mathcal\{M\}\_\{<t\}\\cup\\bigl\(\\\{x\_\{t\}\\\}\\setminus\\\{\\varnothing\\\}\\bigr\)\(2\)
Episodettcan therefore retrieve only experience from earlier completed queries, while its outcome becomes visible beginning at positiont\+1t\+1\.

### 3\.3Type\-Reliability\-Aware Retrieval Variant

We additionally evaluate a controlled MERIT variant that changes only how the predicted type affects candidate selection and ranking\. It does not use a learned or calibrated confidence score\. Instead, defineh​\(τ\)=1h\(\\tau\)=1forSyntax,Schema Linking, andExecution, andh​\(τ\)=0h\(\\tau\)=0otherwise\. These predefined high\-reliability types are intended to be supported directly by observable DBMS diagnostics; the indicator is not estimated from validation data\. For each polarity, the variant selects

𝒞t,prel=\{𝒯t,p,h​\(τt\(k−1\)\)=1∧\|𝒯t,p\|≥3,ℒt,p,otherwise\.\\mathcal\{C\}^\{\\mathrm\{rel\}\}\_\{t,p\}=\\begin\{cases\}\\mathcal\{T\}\_\{t,p\},&h\(\\tau\_\{t\}^\{\(k\-1\)\}\)=1\\land\|\\mathcal\{T\}\_\{t,p\}\|\\geq 3,\\\\ \\mathcal\{L\}\_\{t,p\},&\\text\{otherwise\}\.\\end\{cases\}\(3\)
Lower\-reliability types use the full legal pool and receive a soft type\-match bonus\. Letrbase​\(x,u\)=0\.75​r^dense​\(x,u\)\+0\.25​r^BM25​\(x,u\)r\_\{\\mathrm\{base\}\}\(x,u\)=0\.75\\,\\widehat\{r\}\_\{\\mathrm\{dense\}\}\(x,u\)\+0\.25\\,\\widehat\{r\}\_\{\\mathrm\{BM25\}\}\(x,u\)\. The variant ranks candidates byrrel​\(x,u\)=rbase​\(x,u\)\+0\.10​\(1−h​\(τ\)\)​𝟏​\[τx=τ\]r\_\{\\mathrm\{rel\}\}\(x,u\)=r\_\{\\mathrm\{base\}\}\(x,u\)\+0\.10\\bigl\(1\-h\(\\tau\)\\bigr\)\\mathbf\{1\}\[\\tau\_\{x\}=\\tau\], whereu=ut\(k\)u=u\_\{t\}^\{\(k\)\}andτ=τt\(k−1\)\\tau=\\tau\_\{t\}^\{\(k\-1\)\}\. The bonus is therefore applied only to lower\-reliability types and is disabled for high\-reliability types, including small\-pool fallback cases\. Figure[2](https://arxiv.org/html/2608.05906#S3.F2)illustrates a schema\-linking episode\. The initial query references a nonexistent column inEnrollment; MERIT retrieves an earlier correction involving the missingCoursesjoin and uses it to generate a revision\. The transition is stored as positive memory only after the benchmark oracle confirms the repaired query\.

![Refer to caption](https://arxiv.org/html/2608.05906v1/x2.png)Figure 2:Example MERIT repair episode\. The shared initial prediction references a nonexistent column, producing a schema\-linking failure\. MERIT retrieves an earlier correction involving the missingCoursesjoin and uses it to generate a revision\. After the benchmark correctness oracle confirms the repaired query, the failed\-to\-correct transition is stored as positive memory and becomes available only to later queries\.

## 4Experiments

### 4\.1Experimental Setup

#### Datasets and evaluation\.

We evaluate on the development sets of Spider and BIRD, comprising1,0341\{,\}034and1,5341\{,\}534queries, respectively\. Spider tests cross\-domain generalization to unseen schemas, whereas BIRD contains larger databases, more domain\-specific questions, and auxiliary evidence provided with each example\. We score final predictions with the official execution evaluators\. A query is counted as correct only when its denotation matches the evaluation target; successful execution alone is insufficient\. All prompt templates and memory\-serialization formats are provided in Appendix[B](https://arxiv.org/html/2608.05906#A2)\.

#### Controlled initialization\.

All methods use the same frozen Qwen2\.5\-7B\-Instruct backbone and the same cached initial SQL prediction for each query\. These predictions are generated once with deterministic decoding and achieve58\.90%58\.90\\%execution accuracy on Spider \(609/1,034609/1\{,\}034\) and38\.40%38\.40\\%on BIRD \(589/1,534589/1\{,\}534\)\. Initially correct queries are finalized immediately\. For every initially incorrect query, all methods receive the same execution feedback, decoding policy, and repair budget ofK=7K=7generations\. The comparison therefore isolates differences in repair strategy rather than initial\-generation quality\.

#### Causal stream protocol\.

We run each method under three query orders, denoted by seeds0,11, and22\. The shared initial predictions remain fixed; only the order in which episodes are processed changes\. Within each seed, all methods observe the same stream\. Memory\-based methods start from an empty store and may retrieve only entries produced by completed episodes at earlier stream positions\. Attempts from the current query remain in its local history and cannot enter global retrieval until the episode terminates\. Each stream order therefore induces a distinct sequence of causally available experience\.

#### Comparison methods\.

Our principal baselines isolate the contribution of cross\-query memory and its organization\.Iterativerepairs using execution feedback and the current episode history, but maintains no global memory\.Dynamic RAGaccumulates earlier repair experiences without MERIT’s polarity separation or hard type conditioning\.Reflexion\-styleaugments repair with verbal reflections derived from failed attempts\. MERIT combines causal cross\-query memory, separate positive and negative pools, error\-type conditioning, and hybrid lexical\-dense ranking\.MERIT \(Type\-reliability\-aware\)is a controlled MERIT variant that applies hard filtering only to predefined high\-reliability failure types and otherwise uses type agreement as a soft ranking bonus\.

#### Metrics and statistical analysis\.

We report final execution accuracy and the number of initially incorrect queries that are eventually repaired\. Repair behavior is characterized by mean repair steps per initial failure and trajectory oscillation, while inference cost is measured by total prompt and output tokens and LLM calls\. Unless otherwise stated, results are the mean and sample standard deviation over the three stream orders\.

Because all methods are aligned on the same queries and initial predictions, we also perform paired query\-level comparisons\. For the three\-seed analysis, we use a query\-cluster bootstrap that resamples each query once while keeping its outcomes across all three stream orders together\.

### 4\.2Results

We analyze four questions: whether cross\-query memory improves stateless repair, whether MERIT outperforms alternative memory organizations, how robust type conditioning is, and how repair gains trade off against inference cost\.

Table 1:Execution accuracy over three stream orders\. Values are mean±\\pmsample standard deviation in percentage points\.Boldandunderlineddenote the best and second\-best results within each dataset; tied best results are both bold\.Table 2:Paired query\-level comparison of MERIT against the principal baselines and the type\-reliability\-aware MERIT variant\.Δ\\Deltais MERIT minus the comparison method\. Intervals are obtained by resampling queries while preserving their outcomes across the three stream orders\.Table 3:Mean repair behavior and inference cost over three stream orders\. “Rep\.” is the number of initial failures repaired; “Steps” is repair steps per initial failure; “Osc\.” is the oscillation rate; and “Tok\.” is total prompt and output tokens in millions\.Boldandunderlineddenote the best and second\-best values within each dataset and metric\.MethodRep\.↑\\uparrowSteps↓\\downarrowOsc\.↓\\downarrowTok\.↓\\downarrowCalls↓\\downarrowSpiderIterative77\.06\.08235\.692\.5293619Reflexion\-style98\.05\.82132\.696\.5976309Dyn\. RAG112\.75\.63132\.205\.2753427MERIT112\.75\.61131\.955\.2743419BIRDIterative137\.36\.23854\.529\.3257429Reflexion\-style197\.05\.97151\.7622\.40713568Dyn\. RAG149\.76\.17253\.9418\.0127366MERIT154\.06\.12853\.1317\.5697325

#### Does cross\-query memory improve repair?

On Spider, all memory\-based methods improve over statelessIterativerepair\. MERIT andDynamic RAGtie at69\.79%69\.79\\%, followed byReflexion\-styleat68\.38%68\.38\\%andIterativeat66\.34%66\.34\\%\. MERIT’s3\.453\.45\-point gain overIterativehas a paired95%95\\%confidence interval of\[1\.97,4\.96\]\[1\.97,4\.96\], providing clear evidence that earlier repair experience benefits later queries\. Its differences fromDynamic RAGandReflexion\-styleare not reliably resolved because both intervals include zero\. On BIRD,Reflexion\-styleperforms best at51\.24%51\.24\\%, followed by MERIT at48\.44%48\.44\\%,Dynamic RAGat48\.15%48\.15\\%, andIterativeat47\.35%47\.35\\%\. MERIT’s1\.091\.09\-point gain overIterativehas an interval of\[0\.00,2\.17\]\[0\.00,2\.17\], indicating weaker evidence than on Spider\.

#### Does structured memory outperform alternative memories?

MERIT andDynamic RAGare not reliably separated: they tie on Spider, and MERIT leads by only0\.280\.28points on BIRD\. Thus, the results do not establish an aggregate benefit from MERIT’s polarity separation and hard type conditioning over untyped dynamic retrieval\. MERIT exceedsReflexion\-styleby1\.421\.42points on Spider, but the paired interval\[−0\.19,3\.03\]\[\-0\.19,3\.03\]includes zero\. On BIRD,Reflexion\-styleleads MERIT by2\.802\.80points, with a MERIT\-minus\-Reflexion interval of\[−4\.15,−1\.46\]\[\-4\.15,\-1\.46\], making it the strongest BIRD method\.

#### How robust is error\-type conditioning?

Hard and type\-reliability\-aware filtering are also not reliably distinguishable\. Hard filtering changes mean accuracy by\+0\.39\+0\.39points on Spider and−0\.20\-0\.20points on BIRD, with intervals of\[−0\.23,1\.03\]\[\-0\.23,1\.03\]and\[−0\.67,0\.28\]\[\-0\.67,0\.28\], respectively\. The opposite directions and zero\-crossing intervals indicate that neither policy is uniformly better, supporting the use of error type as a coarse retrieval prior rather than a definitive partition\.

#### How does memory affect repair behavior?

Memory primarily increases the number of initially failed queries that are eventually repaired\. On Spider, MERIT andDynamic RAGeach repair112\.7112\.7failures on average, compared with98\.098\.0forReflexion\-styleand77\.077\.0forIterative\. MERIT also has the shortest trajectories and lowest oscillation, although its differences fromDynamic RAGare small\. On BIRD,Reflexion\-stylerepairs the most failures \(197\.0197\.0\) and produces the shortest, least oscillatory trajectories\. MERIT ranks second with154\.0154\.0repaired failures, compared with149\.7149\.7forDynamic RAGand137\.3137\.3forIterative\. Across both datasets, differences in trajectory length and oscillation are smaller than differences in repair success\.

#### What is the computational trade\-off?

Higher repair success comes with greater token use\. On Spider, MERIT uses5\.2745\.274million tokens and3,4193\{,\}419calls, compared with2\.5292\.529million tokens and3,6193\{,\}619calls forIterative\.Dynamic RAGhas nearly identical cost, whereasReflexion\-stylerequires6\.5976\.597million tokens and6,3096\{,\}309calls\. On BIRD, MERIT uses17\.56917\.569million tokens and7,3257\{,\}325calls, compared with9\.3259\.325million tokens and7,4297\{,\}429calls forIterative\.Reflexion\-styleachieves the highest accuracy but is also the most expensive, requiring22\.40722\.407million tokens and13,56813\{,\}568calls\. Thus, MERIT is less expensive thanReflexion\-style, but does not reduce absolute token consumption relative to stateless repair\.

## 5Ablation Analysis

We ablate memory polarity, error\-type conditioning, lexical\-dense ranking, and schema\-local retrieval\. All variants use the same frozen backbone, cached initial predictions, three causal stream orders, and repair budgetK=7K=7\. Table[4](https://arxiv.org/html/2608.05906#S5.T4)reports mean execution accuracy and sample standard deviation\. Because several differences are small relative to run variation, we interpret the results as component trends rather than a strict ranking\.

Table 4:Execution accuracy for MERIT ablations over three stream orders\.Δ\\Deltais the change in percentage points relative to full MERIT\.Boldandunderlineddenote the best and second\-best results within each dataset; tied best results are both bold\.#### How much does polarity contribute?

Removing negative memory changes accuracy only modestly:−0\.13\-0\.13points on Spider and−0\.09\-0\.09points on BIRD\. These margins are small relative to variation across stream orders, indicating that verified corrections provide most of the useful signal\. Negative entries still offer a limited warning against previously unsuccessful repair directions, but the results do not identify polarity separation as the principal source of MERIT’s gains\.

#### When does error typing help?

Type\-conditioned retrieval is more useful on Spider\. Removing the type filter lowers accuracy by0\.580\.58points, while Random Same Type remains only0\.090\.09points below full MERIT\. Thus, narrowing retrieval to a plausible failure class already provides substantial structure, even before fine\-grained ranking\. Dense relevance remains important within that class: removing dense reranking produces the largest Spider decline among the retrieval ablations,1\.121\.12points\.

BIRD presents a different regime\. No Type Filter and No Dense Rerank both reach48\.57%48\.57\\%, only0\.130\.13points above full MERIT, while Random Same Type is0\.050\.05points below it\. These differences are small relative to their standard deviations and do not establish a preferred retrieval policy\. The type\-reliability\-aware comparison in Table[2](https://arxiv.org/html/2608.05906#S4.T2)leads to the same conclusion: hard filtering is favored by0\.390\.39points on Spider and disfavored by0\.200\.20points on BIRD, but both confidence intervals include zero\. Error type is therefore useful as an organizing prior, particularly on Spider, rather than as a universally reliable retrieval boundary\.

#### How do lexical and dense ranking interact?

The two retrieval channels behave differently across benchmarks\. On Spider, removing dense reranking lowers accuracy by1\.121\.12points, whereas removing BM25 raises the mean by0\.580\.58points and reduces variance\. This pattern suggests that semantic similarity is better aligned with transferable repair structure, while exact lexical overlap can favor surface\-level matches\. However, the paired interval for the No\-BM25 comparison includes zero, so the evidence does not establish that lexical retrieval is reliably harmful\.

On BIRD, removing BM25 lowers accuracy by0\.400\.40points, while removing dense reranking changes the mean by only\+0\.13\+0\.13points\. Exact overlap in table names, columns, and domain terminology may thus be more informative for BIRD’s larger and more specialized schemas\. A fixed lexical–dense mixture provides a common retrieval policy, but the ablations show that the relative value of its channels is environment dependent\.

#### How transferable is repair experience across schemas?

Schema locality produces the clearest and most consistent effect\. Restricting retrieval to memories from other databases lowers accuracy by0\.930\.93points on Spider and2\.742\.74points on BIRD\. Repair patterns do transfer across schemas, but cross\-database analogies do not fully replace experience from the target database\. Same\-database memories can preserve recurring join paths, table relationships, and domain terminology that are difficult to recover from question similarity or failure type alone\. The larger BIRD degradation highlights the importance of schema\-local experience in domain\-specific databases\.

#### Error\-classifier validation\.

Table[5](https://arxiv.org/html/2608.05906#S5.T5)characterizes the operating regime of the deterministic classifier over425425Spider and945945BIRD initial failures\. Spider is dominated byResult Mismatch\(84\.71%84\.71\\%\), whereas BIRD contains substantially moreSchema Linkingand other failure types\. Despite this difference, accuracy remains near48%48\\%on both datasets, with Macro\-F1 scores of0\.3170\.317and0\.3550\.355\. These results show that the labels provide useful but imperfect routing information rather than definitive diagnoses\. We therefore use error type as a coarse retrieval prior, retain a same\-polarity fallback when the typed pool is small, and separately evaluate a type\-reliability\-aware policy that relaxes hard filtering for less reliable categories\.

Table 5:Initial\-failure composition and provisional classifier performance\. Shares are percentages\. “Result mismatch” denotes executable SQL with an incorrect denotation; “Other” aggregates Aggregation, Execution, Syntax, and Unknown\.

## 6Conclusion

We introduced MERIT, a training\-free framework that learns from execution\-guided Text\-to\-SQL repair through causal cross\-query memory\. MERIT clearly improves over stateless repair on Spider, while its BIRD gain is smaller; it is not reliably separated from Dynamic RAG on either benchmark\. The ablations show that polarity contributes modestly, retrieval design is dataset dependent, and schema\-local experience is consistently valuable\. These results support memory\-based improvement without parameter updates, while showing that no single memory organization is uniformly best\.

## 7Limitations

MERIT assumes access to a denotation\-level correctness signal during repair\. This is appropriate for controlled benchmark evaluation, but it is stronger than the feedback available in many deployed databases, where an agent may observe only execution errors, incomplete tests, or delayed user confirmation\. Our experiments also use a single frozen backbone, Qwen2\.5\-7B\-Instruct, and the development sets of Spider and BIRD\. We therefore do not establish that the same gains or trade\-offs hold for other model families, multilingual or conversational Text\-to\-SQL, or production databases with different execution and security constraints\.

The method is sensitive to how experience is accumulated and organized\. Memory contents depend on query order, and three stream orders capture only a limited portion of this variation\. The deterministic classifier is also coarse: its population\-weighted validation accuracy is approximately48%48\\%, and the broad Result Mismatch category combines multiple underlying semantic errors\. This limits how strongly the results can support hard type\-conditioned retrieval and helps explain why relaxed filtering remains competitive on BIRD\. We also fix the retrieval weights, memory allocation, and fallback policy across both benchmarks rather than conducting a comprehensive sensitivity study\.

Finally, MERIT is not cheaper than stateless repair in total token use\. Although it repairs more failures and makes slightly fewer model calls, retrieved memories lengthen each prompt, resulting in substantially higher token consumption\. Our accounting includes LLM prompt and output tokens but excludes embedding computation, indexing, retrieval latency, and memory\-maintenance overhead\. The comparison set also focuses on matched repair and memory strategies rather than every specialized Text\-to\-SQL agent, so the results should be interpreted as evidence about cross\-query memory design, not as a claim of state\-of\-the\-art Text\-to\-SQL performance\.

## References

- MAGIC: generating self\-correction guideline for in\-context text\-to\-SQL\.Proceedings of the AAAI Conference on Artificial Intelligence39\(22\),pp\. 23433–23441\.External Links:[Document](https://dx.doi.org/10.1609/aaai.v39i22.34511),[Link](https://doi.org/10.1609/aaai.v39i22.34511)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- E\. Chau and M\. Peters \(2025\)Making SQL executable with execution\-guided text\-to\-SQL: a reproducible study on WikiSQL\-style queries\.Artificial Intelligence and Machine Learning Review6\(3\),pp\. 1–17\.External Links:[Document](https://dx.doi.org/10.69987/AIMLR.2025.60301),[Link](https://doi.org/10.69987/AIMLR.2025.60301)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- X\. Chen, M\. Lin, N\. Schärli, and D\. Zhou \(2024\)Teaching large language models to self\-debug\.InThe Twelfth International Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=KuPixIqPiq)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p1.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- Y\. Dai, W\. Xie, X\. Zhuang, T\. Yang, Z\. Liu, H\. Yang, Y\. Yang, Y\. Zhao, P\. Chao, and W\. Jiang \(2026\)ReEx\-SQL: reasoning with execution\-aware reinforcement learning for text\-to\-SQL\.InProceedings of the 64th Annual Meeting of the Association for Computational Linguistics \(Volume 1: Long Papers\),San Diego, California, United States,pp\. 824–847\.External Links:[Document](https://dx.doi.org/10.18653/v1/2026.acl-long.35),[Link](https://aclanthology.org/2026.acl-long.35/)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p1.1)\.
- M\. Deng, A\. Ramachandran, C\. Xu, L\. Hu, Z\. Yao, A\. Datta, and H\. Zhang \(2025\)ReFoRCE: a text\-to\-SQL agent with self\-refinement, format restriction, and column exploration\.InICLR 2025 Workshop on VerifAI: AI Verification in the Wild,External Links:[Link](https://openreview.net/forum?id=OuFIfDBwQd)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- D\. Gao, H\. Wang, Y\. Li, X\. Sun, Y\. Qian, B\. Ding, and J\. Zhou \(2024\)Text\-to\-SQL empowered by large language models: a benchmark evaluation\.Proceedings of the VLDB Endowment17\(5\),pp\. 1132–1145\.External Links:[Document](https://dx.doi.org/10.14778/3641204.3641221),[Link](https://www.vldb.org/pvldb/vol17/p1132-gao.pdf)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p2.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px1.p1.1)\.
- Y\. Gong, C\. Lei, X\. Qin, K\. Vaidya, B\. Narayanaswamy, and T\. Kraska \(2025\)SQLens: an end\-to\-end framework for error detection and correction in text\-to\-SQL\.InAdvances in Neural Information Processing Systems,Vol\.38\.External Links:[Link](https://papers.nips.cc/paper_files/paper/2025/hash/c57812dee8acade8c5e385260b2cde28-Abstract-Conference.html)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- Z\. Gou, Z\. Shao, Y\. Gong, Y\. Shen, Y\. Yang, N\. Duan, and W\. Chen \(2024\)CRITIC: large language models can self\-correct with tool\-interactive critiquing\.InThe Twelfth International Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=Sx038qxjek)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p1.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- J\. Huang, X\. Chen, S\. Mishra, H\. S\. Zheng, A\. W\. Yu, X\. Song, and D\. Zhou \(2024\)Large language models cannot self\-correct reasoning yet\.InThe Twelfth International Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=IkmD3fKBPQ)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p1.1)\.
- S\. Lyu, H\. Luo, Z\. Ou, Y\. Zhu, X\. Shang, Y\. Qin, and M\. Song \(2025\)SQL\-o1: a self\-reward heuristic dynamic search method for text\-to\-SQL\.External Links:2502\.11741,[Document](https://dx.doi.org/10.48550/arXiv.2502.11741),[Link](https://arxiv.org/abs/2502.11741)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- A\. Madaan, N\. Tandon, P\. Gupta, S\. Hallinan, L\. Gao, S\. Wiegreffe, U\. Alon, N\. Dziri, S\. Prabhumoye, Y\. Yang, S\. Gupta, B\. P\. Majumder, K\. Hermann, S\. Welleck, A\. Yazdanbakhsh, and P\. Clark \(2023\)Self\-refine: iterative refinement with self\-feedback\.InAdvances in Neural Information Processing Systems,Vol\.36\.External Links:[Link](https://papers.nips.cc/paper_files/paper/2023/hash/91edff07232fb1b55a505a9e9f6c0ff3-Abstract-Conference.html)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p1.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- W\. Mao, R\. Wang, J\. Guo, J\. Zeng, C\. Gao, P\. Han, and C\. Liu \(2024\)Enhancing text\-to\-SQL parsing through question rewriting and execution\-guided refinement\.InFindings of the Association for Computational Linguistics: ACL 2024,Bangkok, Thailand,pp\. 2009–2024\.External Links:[Document](https://dx.doi.org/10.18653/v1/2024.findings-acl.120),[Link](https://aclanthology.org/2024.findings-acl.120/)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- C\. Packer, S\. Wooders, K\. Lin, V\. Fang, S\. G\. Patil, I\. Stoica, and J\. E\. Gonzalez \(2023\)MemGPT: towards LLMs as operating systems\.External Links:2310\.08560,[Document](https://dx.doi.org/10.48550/arXiv.2310.08560),[Link](https://arxiv.org/abs/2310.08560)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px3.p1.1)\.
- J\. S\. Park, J\. O’Brien, C\. J\. Cai, M\. R\. Morris, P\. Liang, and M\. S\. Bernstein \(2023\)Generative agents: interactive simulacra of human behavior\.InProceedings of the 36th Annual ACM Symposium on User Interface Software and Technology,New York, NY, USA\.External Links:[Document](https://dx.doi.org/10.1145/3586183.3606763),[Link](https://doi.org/10.1145/3586183.3606763)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px3.p1.1)\.
- M\. Pourreza, H\. Li, R\. Sun, Y\. Chung, S\. Talaei, G\. T\. Kakkar, Y\. Gan, A\. Saberi, F\. Ozcan, and S\. Arik \(2025\)CHASE\-SQL: multi\-path reasoning and preference optimized candidate selection in text\-to\-SQL\.InThe Thirteenth International Conference on Learning Representations,External Links:[Link](https://proceedings.iclr.cc/paper_files/paper/2025/hash/974ff7b5bf08dbf9400b5d599a39c77f-Abstract-Conference.html)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px1.p1.1)\.
- M\. Pourreza and D\. Rafiei \(2023\)DIN\-SQL: decomposed in\-context learning of text\-to\-SQL with self\-correction\.InAdvances in Neural Information Processing Systems,Vol\.36\.External Links:[Link](https://papers.nips.cc/paper_files/paper/2023/hash/72223cc66f63ca1aa59edaec1b3670e6-Abstract-Conference.html)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p1.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px1.p1.1)\.
- J\. Shen, C\. Wan, R\. Qiao, J\. Zou, H\. Xu, Y\. Shao, Y\. Zhang, W\. Miao, and G\. Pu \(2026\)Understanding, detecting, and repairing real\-world in\-context\-learning\-based text\-to\-SQL errors\.Proceedings of the ACM on Software Engineering3\(FSE\),pp\. 3722–3745\.External Links:[Document](https://dx.doi.org/10.1145/3808171),[Link](https://doi.org/10.1145/3808171)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px2.p1.1)\.
- N\. Shinn, F\. Cassano, A\. Gopinath, K\. R\. Narasimhan, and S\. Yao \(2023\)Reflexion: language agents with verbal reinforcement learning\.InAdvances in Neural Information Processing Systems,Vol\.36\.External Links:[Link](https://papers.nips.cc/paper_files/paper/2023/hash/1b44b878bb782e6954cd888628510e90-Abstract-Conference.html)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p2.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px3.p1.1)\.
- R\. Sun, S\. O\. Arik, A\. Muzio, L\. Miculicich, S\. K\. Gundabathula, P\. Yin, H\. Dai, H\. Nakhost, R\. Sinha, Z\. Wang, and T\. Pfister \(2024\)SQL\-paLM: improved large language model adaptation for text\-to\-SQL\.Transactions on Machine Learning Research\.External Links:ISSN 2835\-8856,[Link](https://openreview.net/forum?id=rlloVZoKrX)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px1.p1.1)\.
- S\. Yao, J\. Zhao, D\. Yu, N\. Du, I\. Shafran, K\. Narasimhan, and Y\. Cao \(2023\)ReAct: synergizing reasoning and acting in language models\.InThe Eleventh International Conference on Learning Representations,External Links:[Link](https://openreview.net/forum?id=WE_vluYUL-X)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p1.1)\.
- H\. Zhang, R\. Cao, L\. Chen, H\. Xu, and K\. Yu \(2023\)ACT\-SQL: in\-context learning for text\-to\-SQL with automatically\-generated chain\-of\-thought\.InFindings of the Association for Computational Linguistics: EMNLP 2023,Singapore,pp\. 3501–3532\.External Links:[Document](https://dx.doi.org/10.18653/v1/2023.findings-emnlp.227),[Link](https://aclanthology.org/2023.findings-emnlp.227/)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p2.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px1.p1.1)\.
- A\. Zhao, D\. Huang, Q\. Xu, M\. Lin, Y\. Liu, and G\. Huang \(2024\)ExpeL: LLM agents are experiential learners\.Proceedings of the AAAI Conference on Artificial Intelligence38\(17\),pp\. 19632–19642\.External Links:[Document](https://dx.doi.org/10.1609/aaai.v38i17.29936),[Link](https://doi.org/10.1609/aaai.v38i17.29936)Cited by:[§1](https://arxiv.org/html/2608.05906#S1.p2.1),[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px3.p1.1)\.
- Y\. Zhao, S\. Chen, J\. Zhang, and Z\. Li \(2025\)ReCode: improving LLM\-based code repair with fine\-grained retrieval\-augmented generation\.InProceedings of the 34th ACM International Conference on Information and Knowledge Management,New York, NY, USA,pp\. 4368–4378\.External Links:[Document](https://dx.doi.org/10.1145/3746252.3761035),[Link](https://doi.org/10.1145/3746252.3761035)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px3.p1.1)\.
- W\. Zhong, L\. Guo, Q\. Gao, H\. Ye, and Y\. Wang \(2024\)MemoryBank: enhancing large language models with long\-term memory\.Proceedings of the AAAI Conference on Artificial Intelligence38\(17\),pp\. 19724–19731\.External Links:[Document](https://dx.doi.org/10.1609/aaai.v38i17.29946),[Link](https://doi.org/10.1609/aaai.v38i17.29946)Cited by:[§2](https://arxiv.org/html/2608.05906#S2.SS0.SSS0.Px3.p1.1)\.

## Appendix AMERIT Correction–Accumulation Loop

Algorithm 1MERIT causal correction\-accumulation loop1:Ordered stream

\{\(qt,St,at,Dt,yt\(0\)\)\}t=1N\\\{\(q\_\{t\},S\_\{t\},a\_\{t\},D\_\{t\},y\_\{t\}^\{\(0\)\}\)\\\}\_\{t=1\}^\{N\}, parser

PP, evaluator

VV, budget

KK
2:

ℳ\+←∅\\mathcal\{M\}^\{\+\}\\leftarrow\\varnothing;

ℳ−←∅\\mathcal\{M\}^\{\-\}\\leftarrow\\varnothing
3:for

t=1,…,Nt=1,\\ldots,Ndo

4:Evaluate shared prediction

yt\(0\)y\_\{t\}^\{\(0\)\}
5:if

yt\(0\)y\_\{t\}^\{\(0\)\}is correctthen

6:Finalize without creating repair memory

7:continue

8:endif

9:

Ht←\[yt\(0\)\]H\_\{t\}\\leftarrow\[y\_\{t\}^\{\(0\)\}\];

solved←false\\mathrm\{solved\}\\leftarrow\\textbf\{false\}
10:for

k=1,…,Kk=1,\\ldots,Kdo

11:Classify the current failure type

τt\(k−1\)\\tau\_\{t\}^\{\(k\-1\)\}
12:Construct the legal earlier\-memory pool

13:Retrieve up to three positive and one negative entries

14:Build prompt from current context,

HtH\_\{t\}, and retrieval

15:Generate one repair

yt\(k\)←P​\(pt\(k\)\)y\_\{t\}^\{\(k\)\}\\leftarrow P\(p\_\{t\}^\{\(k\)\}\)
16:Append

yt\(k\)y\_\{t\}^\{\(k\)\}to

HtH\_\{t\}and evaluate it

17:if

yt\(k\)y\_\{t\}^\{\(k\)\}is correctthen

18:Encode final failed\-to\-correct transition as

xt\+x\_\{t\}^\{\+\}
19:

solved←true\\mathrm\{solved\}\\leftarrow\\textbf\{true\}
20:break

21:endif

22:endfor

23:if

¬solved\\neg\\mathrm\{solved\}then

24:Encode final unsuccessful direction as

xt−x\_\{t\}^\{\-\}
25:endif

26:Insert finalized

xtx\_\{t\}into memory⊳\\trianglerightvisible only for positions\>t\>t

27:endfor

## Appendix BPrompt Templates

MERIT supplies no separate system prompt\. Each template below is passed as a single user message through the model’s native chat template\. Placeholders enclosed in braces are replaced at inference time\. Spider omits all BIRD\-specific evidence blocks\. MERIT Full does not generate local reflections, so the corresponding field in its repair prompt is always rendered as\(none\)\.

### B\.1Shared Initial SQL Generation

The same initial\-generation prompt is used to produce the cached SQL prediction shared by all repair methods\. The prompt\-version identifier isspider\-initial\-v3orbird\-initial\-v3, depending on the benchmark\.

Listing 1:Shared initial SQL\-generation prompt\.PROMPT\_VERSION:\{spider\-initial\-v3\|bird\-initial\-v3\}

YouareanexpertSQLitedeveloper\.ProduceoneSQLqueryforthequestion\.

DATABASESCHEMA:

\{DATABASE\_SCHEMA\}

\{BIRD\_CONTEXT\_IF\_APPLICABLE\}

QUESTION:

\{QUESTION\}

RULES:

\-Useonlyexacttableandcolumnnamesfromtheschema\.

\-DonotcreatetableorcolumnaliaseswithAS\.

\-Returnexactlyonequery;donotprovidealternatives\.

\-PutthefinalSQLbetween<answer\>and</answer\>tags\.

For BIRD,BIRD\_CONTEXT\_IF\_APPLICABLEis replaced with the following block\. Spider receives no corresponding block\.

Listing 2:BIRD\-specific evidence block for initial generation\.EXTERNALKNOWLEDGE/EVIDENCE:

\{BIRD\_EVIDENCE\}

BIRDRULES:

\-Implementtheevidenceformulaorcomputationexactly\.

\-Wrapcolumnnamescontainingspacesorspecialcharactersinbackticks,forexample‘ColumnName‘\.

### B\.2MERIT Repair Generation

Listing[3](https://arxiv.org/html/2608.05906#LST3)gives the central repair prompt used after an unsuccessful SQL attempt\. The prompt contains the current failure signal, complete local attempt history, and retrieved positive and negative memories\. The prompt\-version identifier isspider\-repair\-v3orbird\-repair\-v3\.

Listing 3:MERIT repair prompt\.PROMPT\_VERSION:\{spider\-repair\-v3\|bird\-repair\-v3\}

YouareanexpertSQLitedeveloperrepairinganunsuccessfulquery\.

CONFIRMEDSUCCESSFULREPAIRDIRECTIONS:

\{RETRIEVED\_POSITIVE\_MEMORIES\_OR\_\(none\)\}

OBSERVEDFAILEDDIRECTIONS:

\{RETRIEVED\_NEGATIVE\_MEMORIES\_OR\_\(none\)\}

LOCALREFLECTIONSFROMTHISEPISODE:

\(none\)

CURRENTFEEDBACK:

Status:\{DENOTATION\_MISMATCH\|EXECUTION\_ERROR\|TIMEOUT\}

Currenterrortype:\{ERROR\_TYPE\}

DBerror:\{DATABASE\_ERROR\_OR\_\(none\)\}

DATABASESCHEMA:

\{DATABASE\_SCHEMA\}

\{BIRD\_CONTEXT\_IF\_APPLICABLE\}

QUESTION:

\{QUESTION\}

LOCALATTEMPTHISTORY:

\{ALL\_PREVIOUS\_SQL\_ATTEMPTS\}

REPAIRRULES:

\-ProduceanewSQLqueryratherthanrepeatingapriorattempt\.

\-Useonlyexacttableandcolumnnamesfromtheschema\.

\-Treatfaileddirectionsonlyasobservedevidence;donotinventareason\.

\-PutexactlyonefinalSQLquerybetween<answer\>and</answer\>tags\.

For BIRD, the schema section is followed by the same evidence block shown in Listing[2](https://arxiv.org/html/2608.05906#LST2)\.

### B\.3Memory Serialization

Retrieved positive memories are rendered as verified failed\-to\-correct transitions:

Listing 4:Positive\-memory serialization\.\[Confirmedsuccessfulrepair\{INDEX\}\]

EntryID:\{ENTRY\_ID\}

Errortype:\{ERROR\_TYPE\}

Failurecontext:\{PREVIOUS\_FAILURE\_CONTEXT\}

Observedsuccessfuldirection:\{FAILED\_SQL\_TO\_CORRECT\_SQL\_TRANSITION\}

SQLdelta:\{SQL\_CHANGE\}

Negative memories describe only an observed unsuccessful direction and its recorded outcome:

Listing 5:Negative\-memory serialization\.\[OBSERVEDFAILEDDIRECTION\{INDEX\}\]

EntryID:\{ENTRY\_ID\}

Errortype:\{ERROR\_TYPE\}

Failurecontext:\{FAILURE\_CONTEXT\}

AttemptedSQLdelta:\{SQL\_CHANGE\}

Observedoutcome:\{OUTCOME\}

ObservedDBerror:\{DATABASE\_ERROR\}

The complete local trajectory is serialized in chronological order\. Because repair is invoked only after an unsuccessful attempt, every SQL query included in this block has already been observed to be incorrect\.

Listing 6:Local attempt\-history serialization\.\[Attempt1\-observedunsuccessful\]

\{INITIAL\_SQL\}

\[Attempt2\-observedunsuccessful\]

\{FIRST\_REPAIR\_SQL\}

\.\.\.

\[AttemptN\-observedunsuccessful\]

\{LATEST\_REPAIR\_SQL\}

### B\.4Reflexion\-Style Baseline

The following prompt is used only by the Reflexion\-style baseline and is not used by MERIT Full\. It asks the frozen model to summarize the observed trajectory without generating another SQL query or asserting an unobserved failure cause\. The prompt\-version identifier isspider\-reflection\-v3orbird\-reflection\-v3\.

Listing 7:Reflection\-generation prompt used by the Reflexion\-style baseline\.PROMPT\_VERSION:\{spider\-reflection\-v3\|bird\-reflection\-v3\}

Writeaconcisedebuggingreflectionusingonlytheobservedattemptoutcomes\.

DonotclaimanunobservedcauseanddonotproducethenextSQLquery\.

DATABASESCHEMA:

\{DATABASE\_SCHEMA\}

\{BIRD\_CONTEXT\_IF\_APPLICABLE\}

QUESTION:

\{QUESTION\}

CURRENTERRORTYPE:\{ERROR\_TYPE\}

ATTEMPTSANDOBSERVEDOUTCOMES:

\[Attempt1\]

SQL:\{SQL\_1\}

Outcome:status=\{STATUS\_1\};db\_error=\{ERROR\_1\_OR\_\(none\)\}

\[Attempt2\]

SQL:\{SQL\_2\}

Outcome:status=\{STATUS\_2\};db\_error=\{ERROR\_2\_OR\_\(none\)\}

\.\.\.

Putthereflectionbetween<reflection\>and</reflection\>tags\.

## Appendix CDeterministic Online Error Classifier

The online classifier is conservative and uses only observed DBMS diagnostics and execution status\. It does not inspect the SQL abstract syntax tree or infer semantic errors from query structure\. Rules are evaluated in the order shown in Table[6](https://arxiv.org/html/2608.05906#A3.T6), and the first matching rule determines the output\.

Table 6:Ordered deterministic rules used by the online failure classifier\.The classifier does not diagnose join, ordering, limit, aggregation logic, or other semantic subtypes from SQL shape\. Any broader semantic taxonomy used for manual analysis is therefore distinct from the labels produced by the online classifier\.

## Appendix DRetrieval and Implementation Details

Table[7](https://arxiv.org/html/2608.05906#A4.T7)reports the executed configuration used for the main MERIT experiments and its retrieval\-policy variants\.

Table 7:Executed retrieval, memory, generation, and feedback settings\.#### Dense retrieval\.

The dense encoder isBAAI/bge\-large\-en\-v1\.5at the revision listed in Table[7](https://arxiv.org/html/2608.05906#A4.T7)\. Sentence Transformers 3\.2\.1 producesL2L\_\{2\}\-normalized vectors, which are stored in a FAISSIndexFlatIPindex\. Dense relevance is the inner product of the normalized query and memory vectors and is therefore equivalent to cosine similarity\.

The dense retrieval query concatenates the current question, current SQL, current failure context, and predicted error type\. Dense memory text concatenates the source question, source schema, failure context, normalized SQL transformation, error type, observed outcome, and observed DBMS error\.

#### Lexical retrieval\.

The lexical channel uses a custom BM25 implementation\. Both retrieval queries and memory documents are lowercased and tokenized with\[a\-z0\-9\_\]\+\. For queryqqand candidate memorymm, the lexical score is

BM25⁡\(q,m\)=∑w∈qIDF⁡\(w\)​g​\(w,m\)\\operatorname\{BM25\}\(q,m\)=\\sum\_\{w\\in q\}\\operatorname\{IDF\}\(w\)\\,g\(w,m\)\(4\)where the term\-frequency saturation factor is

g​\(w,m\)=tf⁡\(w,m\)​\(k1\+1\)tf⁡\(w,m\)\+k1​\(1−b\+b​\|m\|/ℓ¯\)g\(w,m\)=\\frac\{\\operatorname\{tf\}\(w,m\)\(k\_\{1\}\+1\)\}\{\\operatorname\{tf\}\(w,m\)\+k\_\{1\}\\left\(1\-b\+b\|m\|/\\bar\{\\ell\}\\right\)\}\(5\)and the inverse\-document\-frequency term is

IDF⁡\(w\)=log⁡\(1\+N−df⁡\(w\)\+0\.5df⁡\(w\)\+0\.5\)\\operatorname\{IDF\}\(w\)=\\log\\left\(1\+\\frac\{N\-\\operatorname\{df\}\(w\)\+0\.5\}\{\\operatorname\{df\}\(w\)\+0\.5\}\\right\)\(6\)whereNNis the number of memories in the selected candidate polarity pool,df⁡\(w\)\\operatorname\{df\}\(w\)is the number of memories containing tokenww,tf⁡\(w,m\)\\operatorname\{tf\}\(w,m\)is its frequency inmm, andℓ¯\\overline\{\\ell\}is the mean document length in that pool\. We usek1=1\.5k\_\{1\}=1\.5andb=0\.75b=0\.75\. Corpus statistics are recomputed after candidate selection, independently for the positive and negative pools\.

BM25 memory text contains the source question, failure context, SQL delta, error type, observed outcome, observed DBMS error, and observed successful direction when one exists\.

#### Normalization and hybrid ranking\.

Dense and BM25 scores are normalized independently within each selected candidate polarity pool\. For score functionss, candidatemm, and pool𝒞t,p\\mathcal\{C\}\_\{t,p\}, normalization is

s^​\(m\)=\{s​\(m\)−sminsmax−smin,smax\>smin,0,otherwise,\\widehat\{s\}\(m\)=\\begin\{cases\}\\dfrac\{s\(m\)\-s\_\{\\min\}\}\{s\_\{\\max\}\-s\_\{\\min\}\},&s\_\{\\max\}\>s\_\{\\min\},\\\\\[6\.0pt\] 0,&\\text\{otherwise\},\\end\{cases\}\(7\)wheresmins\_\{\\min\}andsmaxs\_\{\\max\}are computed over𝒞t,p\\mathcal\{C\}\_\{t,p\}\. Full MERIT then ranks candidates using0\.75​s^dense\+0\.25​s^BM250\.75\\widehat\{s\}\_\{\\mathrm\{dense\}\}\+0\.25\\widehat\{s\}\_\{\\mathrm\{BM25\}\}, as defined in the full\-MERIT ranking function\. Positive and negative memories are ranked separately, and retrieval returns at most three positive and one negative entry\.

For the type\-reliability\-aware variant, the0\.100\.10type\-match bonus is applied only to lower\-reliability predicted types, as specified by the type\-reliability\-aware ranking function\. Ranking ties are resolved by descending dense score, descending BM25 score, descending type\-match score, and finally ascending deterministic memory ID\.

#### Memory and generation configuration\.

Memory entries use format version 3 and are stored in separate positive and negative JSONL files\. Positive entries contain an oracle\-confirmed failed\-to\-correct transition, whereas negative entries contain the final observed unsuccessful direction from an unresolved episode\. Entries are indexed only after episode finalization\.

All methods use themerit\-prompts\-v3prompt family and the same greedy decoding configuration\. Sampling is disabled, temperature is zero, and each initially incorrect query receives at most seven repair generations after the shared initial prediction\. The complete prompt and memory\-serialization templates are provided in Appendix[B](https://arxiv.org/html/2608.05906#A2)\.

相似文章

学习检索:面向文本到SQL智能体的双层长期记忆

arXiv cs.CL

本文提出了MERIT,一种面向交互式文本到SQL智能体的动态多时域记忆检索框架,它使用情节级别和回合级别的记忆,并通过强化学习以及用于密集奖励的过程奖励模型优化的学习检索策略。在BIRD-Interact和Spider2-Snow上的实验表明,MERIT在成功率上优于静态和单时域动态基线,同时需要更少的交互轮次。

基于蒙特卡洛树搜索的多智能体系统自主修复

arXiv cs.LG

本文提出MARS,一种基于蒙特卡洛树搜索的多智能体系统自主修复框架,以及StateMAS,一个包含1,310条故障轨迹的基准。实验表明,MARS在修复准确率上 consistently 优于现有方法,且 token 成本相当。

MEMOREPAIR:智能体记忆中的屏障优先级联修复

arXiv cs.AI

本文介绍了 MemoRepair,这是一种针对智能体记忆的屏障优先级联修复协议,旨在解决源数据变更时衍生工件过时的问题。实验表明,与穷举修复方法相比,MemoRepair 显著降低了失效记忆的暴露率和修复成本。