arXiv:2605.02815cs.CL2026-05

FlexSQL通过灵活探查和执行提升文本转SQL准确性

FlexSQL: Flexible Exploration and Execution Make Better Text-to-SQL Agents

论文配图:FlexSQL: Flexible Exploration and Execution Make Better Text-to-SQL Agents
图 1 · 摘自论文原文
  • 支持任意阶段探查模式、检查数据、运行验证查询
  • 在Spider2-Snow上达65.4%准确率,超越更强模型
  • 适合需要高可靠性的数据库交互系统开发者

在大型分析型数据库上进行文本转SQL,需应对复杂模式、歧义查询,并基于真实数据做出决策。现有系统多采用固定流程,仅在前期一次性获取模式信息,后续仅用于纠错,难以挽回早期错误。本文提出FlexSQL,其核心设计为灵活的数据库交互:代理可在推理过程中任意阶段探索模式结构、检查数据值、执行验证查询。FlexSQL生成多种执行计划以覆盖不同查询解释,根据任务选择用SQL或Python实现,并采用两级修复机制,可从代码级错误回溯至计划级修改。在Spider2-Snow数据集上,使用gpt-oss-120b时,取得65.4%的准确率,优于使用更强更大模型(如gpt-o3和DeepSeek-R1)的开源基线。当集成到通用编程代理(Claude Code中的技能)中时,在Spider2-Snow上相对提升超10%。进一步分析表明,灵活探查与灵活执行共同贡献了性能优势,凸显灵活性作为关键设计原则的重要性。代码已公开于https://github.com/StringNLPLAB/FlexSQL。

原文摘要 · Abstract (English)

Text-to-SQL over large analytical databases requires navigating complex schemas, resolving ambiguous queries, and grounding decisions in actual data. Most current systems follow a fixed pipeline where schema elements are retrieved once upfront and the database is only revisited for post-hoc repair, limiting recovery from early mistakes. We present FlexSQL, a text-to-SQL agent whose core design principle is flexible database interaction: the agent can explore schema structure, inspect data values, and run verification queries at any point during reasoning. FlexSQL generates diverse execution plans to cover multiple query interpretations, implements each plan in either SQL or Python depending on the task, and uses a two-tiered repair mechanism that can backtrack from code-level errors to plan-level revisions. On Spider2-Snow, using gpt-oss-120b, FlexSQL achieves a 65.4\% score, outperforming strong open-source baselines that use stronger, larger models such as gpt-o3 and DeepSeek-R1. When integrated into a general-purpose coding agent (as skills in Claude Code), our approach yields over 10\% relative improvement on Spider2-Snow. Further analysis shows that flexible exploration and flexible execution jointly contribute to the effectiveness of our approach, highlighting flexibility as a key design principle. Our code is available at: https://github.com/StringNLPLAB/FlexSQL

文本转SQL数据库智能推理优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。