arXiv:2609.04641cs.AISep 2026

Manuscript Offprint

arXiv:2609.04641

A Cost-Aware Agentic Architecture for NL-to-SQL over Nested Enterprise Schemas, with a New Benchmark

Yoga Sri Varshan Varadharajan, Ajay Yadav, Ritesh Goru, Prateek Chaudhury, Constantine Caramanis, Prateek Jain, Divyateja Pasupuleti, Sunil Kumar Pandey

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Natural-language-to-SQL systems have advanced rapidly on academic benchmarks, yet production enterprise schemas exhibit graph-like, semi-structured, deeply nested structure that current benchmarks do not measure. We make two complementary contributions. First, we introduce the DevRev NL2SQL benchmark: 900 execution-verified queries with nested-type and link-graph structure, accompanied by the Semantic Depth Score (SDS), a schema-agnostic rubric for analytical reasoning depth. Second, we present a cost-aware single-generation agentic architecture whose schema-selection, metadata-retrieval, and error-repair components are designed for the requirements this regime imposes. On the DevRev NL2SQL benchmark the system attains 91.7% answer correctness, a margin of 54.6 percentage points over the next-best baseline; on the Spider 2.0 Snowflake public dataset, it is competitive with leading systems at a single-generation operating point.

1 Introduction

Natural-language interfaces to SQL have advanced rapidly in recent years, with strong results on academic benchmarks including Spider 1.0 (Yu et al., 2018), BIRD (Li et al., 2024), and Spider 2.0 (Lei et al., 2025).

Deploying NL2SQL on production enterprise data exposes a class of structural challenges that the current benchmark suite does not characterize. Modern enterprise systems of record are often platforms organized around tickets, issues and other workflow objects. These evolve into graph-like, semi-structured data models. Their schemas contain typed ARRAY[STRUCT] columns whose elements have explicit sub-field signatures, polymorphic foreign-key relationships mediated through

typed link arrays, and deeply nested objects with multiple levels of field nesting. Analytical questions over such systems require reasoning over array elements, traversing typed link graphs, and producing SQL that combines LATERAL FLATTEN, conditional aggregation, and enum-constrained filters.

Existing benchmarks emphasize flat relational schemas with primitive-typed columns. Spider 2.0-Snow, for example, contains 7,860 tables across 152 databases, but every table is defined by a flat CREATE TABLE DDL with primitive-typed columns, only 5% of tables carry table-level descriptions, and the corpus contains essentially no queries that exercise nested-type traversal. DevRev fields, in contrast, carry English descriptions that document operational intent. The semi-structured, link-graph regime, together with this schema-as-documentation property, is largely unmeasured by the current benchmark suite.

This regime poses important challenges. Graph-like and polymorphic schemas require an iterative, feedback-driven schema-selection mechanism, to better surface the set of tables a query needs. When columns are typed ARRAY[STRUCT], producing the correct LATERAL FLATTEN requires the sub-field schema and representative sample values inside the array and not the column type signature alone. Failure modes specific to nested types are diverse and structured (improper LATERAL use, single-element UNNEST, malformed type conversions over nested fields, ambiguous flattening aliases). Generic retry-with-error-message strategies become suboptimal. These observations motivate the architecture: iterative schema discovery, metadata-rich retrieval, and a structured error model.

Inference cost is a second consideration. Many leading Spider 2.0 systems employ tournament-style candidate selection (Pourreza et al., 2025; Gao et al., 2024b; Wang et al., 2025). On enterprise data with longer schema, longer candidate SQL bodies, slower nested-type executions, and more

*University of Texas at Austin †DevRev, USA ‡DevRev, Bengaluru, India failure modes that each trigger a retry, the per-query base cost is elevated; this motivates studying single-generation architectures. Our approach could in principle be composed with multi-candidate generation approaches.

A new benchmark for nested enterprise schemas. We introduce and will release the DevRev NL2SQL dataset: 900 execution-verified natural-language queries grounded in a production Snowflake schema with 30 core entity types (190 total schema variants including custom subtypes and snap-in integrations), 13,898 fields, 2,036 typed ARRAY[STRUCT] columns, 1,412 STRUCT-typed or nested fields, and up to four levels of nesting (release details in Appendix A).

A cost-aware single-generation agentic architecture. The system has five components. An LLM-driven schema-discovery loop browses a pre-computed knowledge graph through tool calls and re-invokes those tools on schema-coverage errors, broadening context in response to execution feedback. A structured error taxonomy of 15+ classes maps each execution failure to a targeted repair directive.A pre-execution query verifier audits the SQL for structural flaws. A deterministic checker chain combines static checks with rewriters that auto-fix cross-dialect functions and identifier casing. A dynamic cheatsheet (Suzgun et al., 2026) accumulates transferable SQL rules across queries. A semantic validator inspects executed results against the original question and rejects clear contradictions. The system uses a single generation trajectory per query and does not require fine-tuning. On the DevRev benchmark our system attains 91.7% correctness on the full 900-query corpus and 91.5% on the high-SDS subset (SDS ≥ 11); on the Spider 2.0 Snowflake public leaderboard it is competitive with leading systems at a single-generation operating point.