cs.AIAug 24, 2026

Beyond the Harness: End-to-End Optimization of Context Artifacts for Enterprise Text-to-SQL

Authors: Kate Gwimm, Carson Eisenach

Organizations: Amazon

Abstract

Deploying LLMs for enterprise Text-to-SQL is bottlenecked less by the model than by what context reaches it: business logic spans thousands of tables, and no model can ingest a full catalog at once. We argue that the most effective place to intervene is therefore the knowledge-base context the model consumes, and that this context should be constructed from historical usage rather than tuned for as a fixed input. Using a query-DAG decomposition--the same family of intermediates that enterprise benchmarks like BEAVER annotate, here recovered from production SQL--we compare the value of oracle query graphs versus retrieved knowledge-base context. In this ablation, retrieved knowledge-base context provides the largest marginal improvement when added to the full oracle graph. Building on this, we optimize a distillation procedure that turns historical query profiles into reusable SQL reference cards. On a benchmark of 5176 production queries from a major online retailer, optimizing these context artifacts yields larger gains (∼12{\sim}12--25%25\% AST similarity) than optimizing the retrieval harness (∼3{\sim}3--12%12\%). On the public BEAVER benchmark, which lacks the production-usage signals available in our internal setting, the picture is more mixed: table cards alone perform about the same as raw historical SQL. The best optimized variant retrieves both cards and raw SQL, scoring 9.00%9.00\% versus 6.33%6.33\% (p-value 0.120.12) for the comparable baseline on a held-out N=300N{=}300 subset, using retrieved context and harness changes but no agentic loop.

Figures & tables

Appendix figures & tables4 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. EntSQL: A Benchmark for Grounding Text-to-SQL in Long-Context Enterprise Knowledge

    Jun 2, 2026Chengxi Liao, Tao Xu, Zulong Chen +7LLM GroundingText-to-SQL

  2. Schema-Free Text-to-SQL: Learning Enterprise Database Structure from Query Logs

    Oct 24, 2026Ömer Faruk Akgül, Nikhil Kapahi, Prajit Reddy MuppidiText-to-SQLGraph Retrieval-Augmented Generation

  3. BIRD-History: A Benchmark for History-Driven Text-to-SQL with Fine-Grained Knowledge Annotations

    Aug 29, 2026Yunfan Zhou, Qiming Shi, Yizhou Yang +2Text-to-SQLText-to-SQL Evaluation