用自动分析提升企业级文本转SQL的准确率与鲁棒性
ProSPy: A Profiling-Driven SQL-Python Agentic Framework for Enterprise Text-to-SQL

- 通过自动分析数据结构,逐步缩小无关表范围
- 在Spider 2.0-Lite和Snow上分别达60.15%和60.51%执行准确率
- 适合需要跨数据库方言、处理复杂查询的企业场景
大语言模型虽推动了文本转SQL的发展,但在企业级数据库应用中仍面临挑战:数据库模式庞大异构、元数据不全、方言差异显著,且分析问题常需多步查询。为此,我们提出ProSPy,一种基于分析驱动的SQL-Python智能体框架。该框架将推理过程分为四阶段:首先通过自动分析提取细粒度数据证据;其次逐步裁剪大模式为任务相关上下文;再通过无方言依赖的SQL接口获取中间视图;最后用Python实现灵活下游分析。此设计结合了SQL在大数据集上的效率与Python分析的灵活性,降低对不可靠元数据的依赖,提升跨方言鲁棒性。在Spider 2.0-Lite和Spider 2.0-Snow上的实验表明,ProSPy在使用Claude-4.5-Opus时,无需多数投票即分别达到60.15%和60.51%的执行准确率,显著优于现有强基线模型。进一步分析显示,其对SQL方言变化具有强鲁棒性,并在模式召回率与精确率间取得良好平衡。
原文摘要 · Abstract (English)
Large language models have substantially advanced Text-to-SQL systems, yet applying them to enterprise-scale databases remains challenging. Real-world databases often contain large and heterogeneous schemas, incomplete metadata, dialect-specific SQL syntax, and complex analytical questions that are difficult to solve with a single SQL query. To address these challenges, we propose ProSPy, a Profiling-driven SQL--Python agentic framework for enterprise-scale Text-to-SQL. ProSPy structures the reasoning process into four stages: it first extracts fine-grained data evidence through automatic profiling, progressively prunes large schemas into task-relevant contexts, fetches intermediate views through a dialect-agnostic SQL interface, and finally performs flexible downstream analysis with Python. This design combines the efficiency of SQL over large databases with the flexibility of Python-based analysis, while reducing reliance on unreliable metadata and improving robustness across SQL dialects. Experiments on Spider 2.0-Lite and Spider 2.0-Snow show that ProSPy consistently outperforms strong baselines with both open-source and proprietary models, achieving execution accuracies of 60.15% and 60.51% with Claude-4.5-Opus, without majority voting. Further analysis shows that ProSPy is robust to SQL dialect variations and achieves a favorable trade-off between schema recall and precision.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。