Table of Contents
Fetching ...

APEX-SQL: Talking to the data via Agentic Exploration for Text-to-SQL

Bowen Cao, Weibin Liao, Yushi Sun, Dong Fang, Haitao Li, Wai Lam

TL;DR

APEX-SQL, an Agentic Text-to-SQL Framework that shifts the paradigm from passive translation to agentic exploration, and introduces a deterministic mechanism to retrieve exploration directives, allowing the agent to effectively explore data distributions, refine hypotheses, and generate semantically accurate SQLs.

Abstract

Text-to-SQL systems powered by Large Language Models have excelled on academic benchmarks but struggle in complex enterprise environments. The primary limitation lies in their reliance on static schema representations, which fails to resolve semantic ambiguity and scale effectively to large, complex databases. To address this, we propose APEX-SQL, an Agentic Text-to-SQL Framework that shifts the paradigm from passive translation to agentic exploration. Our framework employs a hypothesis-verification loop to ground model reasoning in real data. In the schema linking phase, we use logical planning to verbalize hypotheses, dual-pathway pruning to reduce the search space, and parallel data profiling to validate column roles against real data, followed by global synthesis to ensure topological connectivity. For SQL generation, we introduce a deterministic mechanism to retrieve exploration directives, allowing the agent to effectively explore data distributions, refine hypotheses, and generate semantically accurate SQLs. Experiments on BIRD (70.65% execution accuracy) and Spider 2.0-Snow (51.01% execution accuracy) demonstrate that APEX-SQL outperforms competitive baselines with reduced token consumption. Further analysis reveals that agentic exploration acts as a performance multiplier, unlocking the latent reasoning potential of foundation models in enterprise settings. Ablation studies confirm the critical contributions of each component in ensuring robust and accurate data analysis.

APEX-SQL: Talking to the data via Agentic Exploration for Text-to-SQL

TL;DR

APEX-SQL, an Agentic Text-to-SQL Framework that shifts the paradigm from passive translation to agentic exploration, and introduces a deterministic mechanism to retrieve exploration directives, allowing the agent to effectively explore data distributions, refine hypotheses, and generate semantically accurate SQLs.

Abstract

Text-to-SQL systems powered by Large Language Models have excelled on academic benchmarks but struggle in complex enterprise environments. The primary limitation lies in their reliance on static schema representations, which fails to resolve semantic ambiguity and scale effectively to large, complex databases. To address this, we propose APEX-SQL, an Agentic Text-to-SQL Framework that shifts the paradigm from passive translation to agentic exploration. Our framework employs a hypothesis-verification loop to ground model reasoning in real data. In the schema linking phase, we use logical planning to verbalize hypotheses, dual-pathway pruning to reduce the search space, and parallel data profiling to validate column roles against real data, followed by global synthesis to ensure topological connectivity. For SQL generation, we introduce a deterministic mechanism to retrieve exploration directives, allowing the agent to effectively explore data distributions, refine hypotheses, and generate semantically accurate SQLs. Experiments on BIRD (70.65% execution accuracy) and Spider 2.0-Snow (51.01% execution accuracy) demonstrate that APEX-SQL outperforms competitive baselines with reduced token consumption. Further analysis reveals that agentic exploration acts as a performance multiplier, unlocking the latent reasoning potential of foundation models in enterprise settings. Ablation studies confirm the critical contributions of each component in ensuring robust and accurate data analysis.
Paper Structure (86 sections, 6 equations, 3 figures, 7 tables)

This paper contains 86 sections, 6 equations, 3 figures, 7 tables.

Figures (3)

  • Figure 1: A comparison of Text-to-SQL paradigms. (a) Static Schema Prompting relies solely on the schema, causing hallucinations when metadata is ambiguous. (b) Pre-processed Schema Augmentation attempts to enrich context with preliminary data profiling, yet introduces irrelevant noise and token overhead. (c) APEX-SQL introduces Agentic Exploration, employing a hypothesis-verification loop to actively interrogate the database and ground logical reasoning.
  • Figure 2: The proposed APEX-SQL framework. Schema Linking (Top): To navigate massive databases, APEX-SQL first verbalizes a logical plan, serving as a grounded reference for subsequent pruning and verification. It actively verifies the semantic roles of candidate tables through parallel profiling and summarizes key observations for each column. Finally, APEX-SQL refines the schema subgraph by ensuring topological connectivity and recovering missing dependencies via global synthesis. SQL Generation (Bottom):APEX-SQL employs a deterministic retrieval mechanism to map logical operations to specific exploration guidance. Directed by these constraints, it navigates a flexible action space to autonomously profile data distributions, consolidate exploration findings, synthesize candidate queries, or perform a final confirmation check to validate the executable SQL.
  • Figure 3: Performance scaling of GPT-4o and DeepSeek-V3.2 on Spider 2.0-Snow subset ($N=120$) using the oracle schema.