A Semantic-Layer-Mediated Agent for Natural Language to SQL over Heterogeneous Enterprise Databases
1 st Ha Jeong Kim, 2 nd Saksonita Khoeurn, 3 rd Ye Ji Yoon · 2026
Read A Semantic-Layer-Mediated Agent for Natural Language to SQL over Heterogeneous Enterprise Databases by 1 st Ha Jeong Kim, 2 nd Saksonita Khoeurn, 3 rd Ye Ji Yoon (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-2606-31041.txt.
Introduction
Ha Jeong Kim, Saksonita Khoeurn and Ye Ji Yoon present an agent that answers business questions in SQL without ever showing the model a raw database schema. Enterprise databases hold hundreds of tables with opaque column names, several SQL dialects, and questions needing nested aggregation and multi-table joins, so prompting a model with raw schema text yields brittle queries. Their agent instead reasons through a compact intermediate representation, the Semantic Model Query, over a curated semantic layer. A deterministic engine compiles those queries into dialect-correct SQL, which the agent inspects, composes and executes across SQLite, BigQuery and Snowflake backends.
Driven by Gemini 3 Pro, the system reached 94.15% execution accuracy on the 547-task Spider2-snow benchmark of real enterprise tasks on Snowflake. That placed third on the official leaderboard, far above schema-only baselines. The authors also discuss the quality and overfitting tensions of maintaining the semantic layer itself.
Catalog record
| CREATOR | 1 st Ha Jeong Kim, 2 nd Saksonita Khoeurn, 3 rd Ye Ji Yoon |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 22 KB |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2606.31041
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
A Semantic-Layer-Mediated Agent for Natural Language to SQL over Heterogeneous Enterprise Databases Ha Jeong Kim and Saksonita Khoeurn contributed equally to this work. Corresponding author: Saksonita Khoeurn ([email protected]). 1 st Ha Jeong Kim, 2 nd Saksonita Khoeurn, 3 rd Ye Ji Yoon Abstract Natural language to SQL (NL2SQL) over real enterprise databases remains substantially harder than over academic benchmarks: schemas contain hundreds of physical tables with opaque column names, dialects differ across engines, and a single analytical question may require nested aggregation, time-windowed logic, and multi-table joins. Directly prompting a large language model (LLM) with raw schema text exposes the model to this complexity all at once and yields brittle queries. This paper presents the architecture of a semantic-layer-mediated NL2SQL agent that decouples intent from physical execution . Rather than asking the LLM to write SQL against raw tables, the agent reasons over a curated semantic layer through a compact intermediate representation we call the Semantic Model Query (SMQ); a deterministic engine compiles SMQs into dialect-correct SQL, which the agent then inspects, composes, and executes. The system follows a single-tool think–act loop, routes execution across SQLite, BigQuery, and Snowflake backends, and is packaged as an end-to-end evaluation harness. Driven by Gemini 3 Pro, the system attains 94.15% execution accuracy on the 547-task Spider2-snow benchmark—a suite of real-world enterprise NL2SQL tasks executed against Snowflake—the third-highest entry on the official leaderboard and far above schema-only baselines. We describe the component design, the SMQ representation, the agent’s exploration strategy, and the per-backend results, and we discuss the quality and overfitting tensions inherent to maintaining a semantic layer as a context source for an LLM agent. I Introduction Translating natural language questions into executable SQL (NL2SQL) is a long-standing goal for democratizing data access. Recent large language models (LLMs) achieve strong results on academic benchmarks such as Spider [ 2 ] and BIRD [ 3 ] , where schemas are small and questions map fairly directly to single queries. Enterprise settings are different in kind, not merely in degree. The Spider2 benchmark [ 1 ] was introduced precisely to capture this gap: its tasks operate over production data warehouses with hundreds of columns, cryptic naming conventions, dialect-specific functions, and questions whose gold answers routinely span dozens of lines of SQL with common table expressions (CTEs), window functions, and multi-step aggregation. Reported accuracies on Spider2 are far below the near-saturation numbers seen on Spider, confirming that “put the schema in the prompt and ask for SQL” does not transfer to real workloads. We argue that the difficulty has two distinct sources. The first is grounding : the model must discover which physical tables and columns are relevant and how they join, out of a large and poorly self-describing schema. The second is composition : the model must assemble correct, dialect-valid SQL once the right building blocks are known. Conflating these two problems in a single free-form generation step is what makes naive prompting brittle—a single wrong column name or join predicate fails the whole query, and the model has no structured surface on which to recover. This paper presents the architecture of spider2-daquv-quvi , an NL2SQL agent that separates grounding from composition by interposing a semantic layer between the LLM and the database. The semantic layer is a curated, business-oriented description of each database: tables are wrapped as semantic models exposing named dimensions , measures , and metrics , with human-readable descriptions and the physical column expressions they map to. The agent never sees raw schema first; instead it issues a compact, structured query—the Semantic Model Query (SMQ)—against the semantic layer. A deterministic engine compiles each SMQ into dialect-correct SQL and returns it. The agent uses these compiled fragments as verified building blocks : it inspects the physical column expressions and join patterns they reveal, composes them into a final query (adding constructs the SMQ compiler does not support, such as window functions or recursive CTEs), and executes that query against the appropriate backend. The contributions of this paper are: • A system architecture for NL2SQL that mediates LLM reasoning through a semantic layer and a structured intermediate representation (SMQ), decoupling schema grounding from SQL composition (Sections III – IV ). • A single-tool think–act agent loop in which SMQ compilation is used for exploration and direct SQL execution is the single terminal action, together with the prompting strategy that enforces this discipline (Section V ). • A multi-backend execution and evaluation harness that routes queries to SQLite, BigQuery, and Snowflake and scores them under the Spider2 protocol (Section VI ). • An empirical study on the 547-task Spider2-snow benchmark, reporting 94.15% execution accuracy with a per-backend breakdown and a comparison against published leaderboard methods, and a discussion of the practical tension between semantic-layer quality and overfitting to the evaluation set (Sections VII – VIII ). II Related Work Text-to-SQL benchmarks. Spider [ 2 ] established cross-domain, multi-table semantic parsing as a standard task; BIRD [ 3 ] added larger, dirtier databases and an emphasis on efficiency and external knowledge. Spider2 [ 1 ] raised the bar to enterprise-scale warehouses on BigQuery, Snowflake, and local engines, with long, realistic gold queries; it is the benchmark we target. Our work evaluates on the Spider2-snow split. LLM methods for text-to-SQL. Prompting and decomposition methods such as DIN-SQL [ 4 ] , DAIL-SQL [ 5 ] , and C3 [ 6 ] improve single-shot generation through schema linking, few-shot selection, and self-correction. Multi-agent and pipeline systems such as MAC-SQL [ 7 ] and CHESS [ 8 ] introduce specialized decomposer/selector/refiner roles and schema-pruning stages. These approaches operate directly on physical schemas; our system instead routes reasoning through a curated semantic layer, treating compiled SMQ \rightarrow SQL fragments as verified grounding evidence rather than relying on the model to recall physical names from a flat schema dump. Semantic layers. Business-intelligence semantic layers and metrics frameworks (e.g., dbt’s MetricFlow [ 10 ] ) let analysts define dimensions, measures, and metrics once and reuse them across queries. We repurpose this idea as an LLM grounding substrate : the semantic layer is both the model’s view of the data and the source of compilable, dialect-correct SQL. LLM agents and tool use. The think–act paradigm of ReAct [ 9 ] interleaves reasoning traces with tool calls. Our agent adopts a strict single-tool-per-step variant in which one tool (SMQ compilation) is for exploration and another (SQL execution) is the single terminating action, constraining the agent’s action space to reduce error propagation. III System Architecture Fig. 1 shows the end-to-end architecture. The system is organized into four tiers: (1) an orchestration tier that loads benchmark instances and drives batched, parallel execution; (2) the QUVI NL2SQL service that hosts the LLM agent and the semantic layer; (3) a deterministic SMQ-to-SQL engine ; and (4) a multi-backend executor that runs the final SQL against the correct database. Each instance is processed as an independent workflow keyed by an instance identifier and timestamp. Fig. 1: End-to-end architecture. The orchestrator dispatches NL questions to the QUVI service, which runs the agent loop over the semantic layer. SMQs are compiled to SQL by the engine; the final SQL is routed by instance prefix to the SQLite, BigQuery, or Snowflake executor.