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:
- Massive and Heterogeneous Schemas: Databases often contain hundreds of tables with ambiguous naming conventions and deeply nested or semi-structured fields.
- Imprecise Metadata: Documentation is frequently incomplete or unreliable, making it hard for an LLM to understand column semantics.
- Dialect Variations: Different database engines (e.g., Snowflake, BigQuery, SQLite) use distinct SQL dialects, leading to syntax errors.
- 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:
- 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
VARIANTcolumns). - 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.
- 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.
- 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.
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