Papers
Topics
Authors
Recent
Search
2000 character limit reached

A Semantic-Layer-Mediated Agent for Natural Language to SQL over Heterogeneous Enterprise Databases

Published 30 Jun 2026 in cs.CL | (2606.31041v1)

Abstract: Natural language-to-SQL (NL2SQL) over real-world enterprise databases remains significantly more challenging than on academic benchmarks. Enterprise schemas often contain hundreds of physical tables with cryptic column names, heterogeneous SQL dialects, and complex analytical workloads requiring nested aggregations, temporal reasoning, and multi-table joins. We present a semantic-layer-mediated NL2SQL agent that decouples semantic intent from physical SQL execution. Rather than generating SQL directly over raw schemas, the agent reasons over a curated semantic layer through a compact intermediate representation called the Semantic Model Query (SMQ). A deterministic compiler translates each SMQ into dialect-specific SQL, providing verified building blocks that the agent composes into the final query. The system employs a constrained think-act loop, supports SQLite, BigQuery, and Snowflake backends, and is integrated into an end-to-end evaluation framework. Using Gemini 3 Pro, the system achieves 94.15% execution accuracy on the 547-task Spider2-snow benchmark, ranking third on the official leaderboard and substantially outperforming schema-only approaches. We describe the system architecture, SMQ representation, agent workflow, evaluation results, and discuss semantic-layer quality and the trade-off between improved grounding and overfitting.

Summary

  • The paper introduces a mediated architecture that separates semantic grounding and SQL synthesis to address the complex challenges of enterprise NL2SQL translation.
  • It details a four-tier system—including orchestration, NL2SQL service, SMQ-to-SQL engine, and multi-backend execution—that ensures robust, auditable query generation.
  • The approach achieves 94.15% execution accuracy on the Spider2-snow benchmark, markedly outperforming traditional schema-only and prompt-based methods.

Semantic-Layer-Mediated NL2SQL Agents for Enterprise Databases

Motivation and Problem Setting

Natural language to SQL (NL2SQL) translation is a pivotal task for democratizing complex data access. Academic datasets like Spider and BIRD have standardized cross-domain semantic parsing, but the typical enterprise scenario presents distinctly greater challenges: schemas with hundreds of cryptically named tables, heterogeneous SQL dialects, and business questions necessitating deeply nested, multi-step queries. Prior approaches relying on schema-only prompting for LLMs exhibit significant fragility in these real-world contexts, as documented by the substantial gap in performance between Spider and the production-grade Spider2 benchmarks.

Enterprise-scale NL2SQL tasks expose two principal sources of difficulty: schema grounding—discovering relevant physical entities and join paths in sprawling, opaque schemas—and compositional SQL synthesis—assembling valid dialect-specific queries from the inferred schema elements. Conflating these dimensions within a single LLM generation step has proven ineffective, prompting the authors to advocate a mediated architecture separating semantic grounding from SQL synthesis.

System Architecture

The proposed spider2-daquv-quvi agent architecture interposes a curated semantic layer between the LLM and the physical databases, operationalized through four principal tiers:

  • Orchestration Tier: Responsible for task loading, parallel dispatching, and workflow management.
  • QUVI NL2SQL Service: Hosts the agent, leverages semantic-layer context, and runs the think–act loop.
  • SMQ-to-SQL Engine: Deterministically compiles structured Semantic Model Queries (SMQs) into dialect-validated SQL by mapping abstract elements to their exact physical expressions and join predicates.
  • Multi-Backend Executor: Routes final SQL to SQLite, BigQuery, or Snowflake, maintaining execution and result integrity.

This architecture ensures agent workflows are well-audited, reproducible, and portable across heterogeneous enterprise backends. Figure 1

Figure 1: End-to-end architecture for semantic-layer-mediated NL2SQL, orchestrating agent workflows from NL questions through SMQ compilation to execution and scoring across multiple backends.

Semantic Layer and Intermediate Representation

A central innovation is the semantic layer, inspired by business-intelligence platforms (e.g., dbt MetricFlow), which abstracts physical schemas into business-named models with described dimensions, measures, and metrics. Each element exposes both a human-readable description (for LLM grounding) and precise expressions (for compilation). Structural context—such as inter-table joins and key transformations—is declared in a dedicated join graph, enabling automated join synthesis and reducing schema exploration burden.

The SMQ serves as a compact, intermediate JSON representation which explicitly names metrics, filters, and group-bys, referencing semantic model elements rather than raw tables or columns. SMQs are compiled into SQL, serving as verified evidence for physical entity mapping; however, SMQ's expressiveness is intentionally limited to common analytical constructs, deferring advanced SQL functionality (CTEs, window functions, recursive queries) to agent composition.

Agent Workflow and Exploration Strategy

The agent implements a constrained think–act loop, restricting each step to a single tool call: listing model elements, compiling SMQs, or executing SQL. SMQ compilation operates strictly as an exploratory tool—never for direct answer submission—revealing grounded column names, table expressions, and join paths. The agent subsequently synthesizes a final SQL query, referencing only compiler-validated physical identifiers, and executes it via the backend. Schema introspection and direct referencing of semantic model names are forbidden, further enforcing mediation discipline.

This workflow delivers two advantages: guided semantic grounding via descriptive context and robust SQL composition by leveraging compiler-certified physical names, confining errors to agent-authored structural additions (e.g., advanced aggregations or nontrivial logic).

Evaluation and Numerical Results

On the Spider2-snow benchmark—containing 547 enterprise NL2SQL tasks over production Snowflake, SQLite, and BigQuery schemas—the system achieves 94.15% execution accuracy, correctly answering 515 instances. This accuracy far exceeds that of schema-only or prompting-only systems (DAIL-SQL + GPT-4o: 2.2%, Spider-Agent: 23–26%, ReFoRCE: 31.3%), establishing semantic-layer mediation as decisively effective in realistic enterprise contexts.

Accuracy breakdowns confirm robustness across database-origin classes, except for native Snowflake (55.6%, due to limited semantic-layer maturity and high-variance sample size), with all other classes exceeding 94%.

Implications and Discussion

The results highlight the semantic layer as the primary lever for accuracy: improvements in element coverage, description quality, and join declarations directly lift per-database performance. However, this also raises overfitting tensions—curating semantic-layer descriptions based on evaluation set risks diluting generalizability for unseen queries or schema changes. The paper advocates rigorous semantic-layer design, separating structural code from descriptive prose and avoiding evaluation-specific annotations.

Failure analysis reveals that most errors stem from incomplete semantic models or join declarations, rather than agent logic. Adapting the SMQ or semantic layer to comprehensively cover advanced SQL constructs may further reduce these residual errors, but maintaining robust abstraction without overfitting remains a critical challenge.

Theoretical and Practical Implications

The semantic-layer-mediated agent architecture demonstrates that formal separation of grounding and composition enables LLMs to operate reliably over complex, heterogeneous enterprise databases. This paradigm not only improves accuracy but also enhances interpretability, auditable workflows, and maintainability, shifting the focus of system development toward high-quality semantic abstraction rather than prompt engineering.

In theory, semantic-layer mediation provides a generalizable substrate for language-agent interaction with arbitrary data backends, suggesting prospects for broader vertical integration and domain-specific abstraction layers. In practice, operational success is bounded primarily by semantic-layer quality, motivating future research on quantifying abstraction robustness, regularizing semantic-layer updates, and developing systematic tools for semantic model evolution.

Conclusion

The paper presents a comprehensive architecture for NL2SQL over heterogeneous enterprise databases, leveraging semantic-layer mediation and a structured SMQ intermediate to achieve state-of-the-art accuracy on the Spider2-snow benchmark. By decoupling schema grounding from SQL composition and mediating all agent reasoning through descriptive, business-oriented models, the approach outperforms schema-only baselines and prompting pipelines. The central challenge moving forward involves advancing semantic-layer coverage and abstraction quality without succumbing to overfitting, a direction with substantial implications for future enterprise AI agents.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.