- 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.
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: 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.
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.