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. Our code is released at https://github.com/Tencent/APEX-SQL-Project.
翻译:基于大语言模型的文本到SQL系统在学术基准测试中表现优异,但在复杂企业环境中仍面临挑战。其核心局限在于依赖静态模式表示,无法有效解决语义歧义问题,也难以扩展至大规模复杂数据库。为此,我们提出APEX-SQL——一种将范式从被动转换转向智能体探索的智能体文本到SQL框架。该框架采用假设-验证循环机制,将模型推理锚定于真实数据。在模式链接阶段,我们通过逻辑规划实现假设语言化、双路径剪枝缩减搜索空间、并行数据剖析验证列角色与真实数据的一致性,并通过全局合成确保拓扑连通性。针对SQL生成,我们引入确定性机制检索探索指令,使智能体能够有效探索数据分布、优化假设并生成语义准确的SQL语句。在BIRD(执行准确率70.65%)和Spider 2.0-Snow(执行准确率51.01%)上的实验表明,APEX-SQL以更低的令牌消耗超越竞争基线。进一步分析显示,智能体探索作为性能倍增器,可解锁基础模型在企业场景中的潜在推理能力。消融研究证实了各组件在确保鲁棒且准确的数据分析中的关键作用。我们的代码已开源至https://github.com/Tencent/APEX-SQL-Project。