NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

ProSPy: A Profiling-Driven SQL-Python Agentic Framework for Enterprise Text-to-SQL

Zhaorui Yang, Huawei Zheng, Sen Yang, Yuhui Zhang, Haoxuan Li, Zhizhen Yu, Xuan Yi, Chen Hou, Defeng Xie, Chao Hu, Minfeng Zhu, Dazhen Deng, Haozhe Feng, Danqing Huang, Yingcai Wu, Peng Chen, Wei ChenarXiv 2026

TL;DR

ProSPy is a novel agentic framework designed to tackle enterprise-scale Text-to-SQL challenges by splitting the problem into two logical phases: SQL-based data retrieval and Python-based analysis. By combining automatic data profiling, progressive schema pruning, and a dialect-agnostic Domain-Specific Language (DSL), ProSPy achieves state-of-the-art execution accuracy on complex enterprise benchmarks using a single trial, completely bypassing the need for expensive test-time scaling strategies like majority voting.

What Problem Does This Paper Address?

While Large Language Models (LLMs) have gotten remarkably good at translating natural language questions into SQL queries on standard benchmarks (like Spider 1.0 or BIRD), they frequently stumble when deployed in real-world enterprise environments.

Enterprise databases present a perfect storm of challenges:

  1. Massive and Heterogeneous Schemas: Databases often contain hundreds of tables with ambiguous naming conventions and deeply nested or semi-structured fields.
  2. Imprecise Metadata: Documentation is frequently incomplete or unreliable, making it hard for an LLM to understand column semantics.
  3. Dialect Variations: Different database engines (e.g., Snowflake, BigQuery, SQLite) use distinct SQL dialects, leading to syntax errors.
  4. Complex Analytical Workflows: Real-world business questions often require multi-step reasoning, intermediate views, and statistical computations that are incredibly difficult—or impossible—to express cleanly in a single SQL query.

Existing agentic approaches try to solve this by repeatedly probing the database or generating multiple candidate queries and using majority voting. However, this introduces massive latency and computational overhead, making them impractical for production enterprise environments.

Methods

ProSPy addresses these challenges by decomposing enterprise-scale data reasoning into a structured, four-stage pipeline:

Figure 1: Overview of ProSPy, which combines a dialect-agnostic DSL for SQL-based retrieval with Python-based analysis to support scalable retrieval, shield SQL dialect differences, and perform complex data analysis for enterprise-scale Text-to-SQL.
  1. Data Profiling: Instead of relying on flawed external metadata or ad-hoc LLM exploration, ProSPy runs automated, templated SQL queries once per database. It extracts fine-grained column-level evidence, infers semantic types (e.g., distinguishing identifiers from metrics), and recursively uncovers the internal structures of complex nested types (like Snowflake's VARIANT columns).
  2. Progressive Schema Pruning: To prevent the LLM from being overwhelmed by massive schemas, ProSPy applies a coarse-to-fine pruning strategy. It first filters out irrelevant tables batch-by-batch, and then refines the remaining tables down to the specific columns necessary for the task.
  3. Agentic Data Fetching via DSL: Rather than forcing the LLM to write complex, dialect-specific SQL directly, the agent generates view definitions using a lightweight, dialect-agnostic Domain-Specific Language (DSL) structured around dimensions, metrics, and conditions. This DSL is then automatically transpiled into the target SQL dialect to materialize intermediate views as CSV files.
  4. Python Analysis: The materialized CSV files are loaded into a secure Python sandbox. Here, the LLM acts as a data analyst, writing flexible Python code (using libraries like pandas) to perform complex multi-step transformations, ranking, and final statistical calculations.
Figure 2: Illustration of the ProSPy framework. ProSPy consists of four stages: (A) data profiling, (B) progressive schema pruning, (C) agentic data fetching, and (D) Python analysis. It extracts structured data evidence from raw tables, prunes large schemas into task-relevant contexts, fetches intermediate views through a dialect-agnostic DSL-to-SQL interface, and performs final analysis with Python interpreter to produce the result CSV.

Datasets

The authors evaluated ProSPy on the Spider 2.0 benchmark, which specifically targets enterprise-level text-to-SQL workflows. They utilized two subsets:

  • Spider 2.0-Lite (547 examples): Covers cross-dialect reasoning across Snowflake, BigQuery, and SQLite.
  • Spider 2.0-Snow (547 examples): Focuses exclusively on complex analytical workflows within the Snowflake dialect.

Key Insights and Ideas

  • The Power of Hybrid Computation (SQL + Python): Forcing an LLM to express an entire multi-step analytical workflow in a single SQL query is a bottleneck. SQL is highly efficient at filtering and aggregating massive datasets inside the database, while Python is far superior for flexible, iterative, downstream logic (like complex ranking or calculating shares).
  • Shielding Dialects with a DSL: Abstracting retrieval intent into a generic DSL decouples semantic understanding from syntax execution. This shields the LLM from having to memorize the subtle syntax quirks of every SQL dialect.
  • Precision Matters in Schema Linking: Traditional schema linking methods prioritize recall (making sure no relevant table is missed), which often leaves too much noise in the prompt. ProSPy proves that achieving a tight balance with high precision drastically reduces the reasoning space and improves final query accuracy.

Key Results

ProSPy consistently outperformed strong baseline frameworks across both open-source and proprietary models:

  • State-of-the-Art Accuracy: Using Claude-4.5-Opus, ProSPy achieved an execution accuracy of 60.15% on Spider 2.0-Lite and 60.51% on Spider 2.0-Snow.
  • No Majority Voting Needed: Unlike competitors like ReForce or LinkAlign, which rely on generating multiple queries and voting to find the right answer, ProSPy achieved these top-tier results in a single trial, drastically reducing latency and cost.
  • Robust Schema Linking: On Spider 2.0-Snow, ProSPy achieved the highest Non-Strict Precision (86.02%) and F1-score (87.40%), vastly outperforming baselines while consuming fewer tokens.

Limitations and Future Work

  • Error Propagation: Because the framework is sequential, it is susceptible to cascading errors. If the agent generates an incorrect intermediate view during the SQL data-fetching stage, the downstream Python analysis will be fed faulty data, leading to an incorrect final answer.
  • Evaluation Scope: While Spider 2.0 is a major step forward, the framework has still only been tested on these specific benchmark subsets. Further evaluation on more diverse, messy, real-world enterprise databases is required to fully validate its generalizability.

Summary updated

BibTeX
@misc{yang2026prospy,
  author = {Zhaorui Yang and Huawei Zheng and Sen Yang and Yuhui Zhang and Haoxuan Li and Zhizhen Yu and Xuan Yi and Chen Hou and Defeng Xie and Chao Hu and Minfeng Zhu and Dazhen Deng and Haozhe Feng and Danqing Huang and Yingcai Wu and Peng Chen and Wei Chen},
  title = {{ProSPy: A Profiling-Driven SQL-Python Agentic Framework for Enterprise Text-to-SQL}},
  year = {2026},
  eprint = {2606.05836},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.05836},
}
Figure