BookSQL: A Large Scale Text-to-SQL Dataset for Accounting Domain

Rahul Kumar, Amar Raja Dibbu, Shrutendra Harsola, Vignesh Subrahmaniam, Ashutosh Modi

Introduction

Text-to-SQL systems—which translate natural language queries into executable SQL—have seen significant advancements recently. However, these systems often struggle when applied to specialized domains like accounting and finance. Researchers have introduced BookSQL, a massive new dataset of 100,000 natural language query and SQL pairs specifically designed to bridge this "domain gap."

Accounting databases are uniquely complex, governed by strict principles such as double-entry bookkeeping and hierarchical charts of accounts. For non-technical financial professionals, querying these databases for insights like "average revenue over the last six years" presents a high barrier to entry. BookSQL provides a high-quality resource to train and evaluate models on these business-critical tasks, revealing that existing state-of-the-art models struggle significantly with the specialized logic and time-based filters required for real-world financial reporting.

Dataset Construction and Methodology

The authors collaborated with financial experts to ensure BookSQL reflects authentic industry practices. The construction pipeline involved four primary stages:

  1. Schema Design: A realistic schema was developed featuring seven core tables, including Master Transactions, Vendors, and Employees, supporting 27 different business types ranging from restaurants to real estate.
  2. Data Generation: The database was populated with 1 million records while maintaining strict financial constraints, such as ensuring debits equal credits for every transaction.
  3. Query Templatization: Experts defined 183 unique "seed" questions, which were expanded into 100,000 pairs by swapping entities and time-based filters.
  4. Complexity Scaling: Queries were categorized into Easy, Medium, and Hard levels. The "Hard" category includes complex joins, nested queries, and multi-step logic.
The BookSQL database schema featuring core accounting tables like Master_Trx and Chart_of_Accounts.

Experimental Results and Key Insights

The researchers benchmarked several state-of-the-art (SOTA) models, including RESDSQL, UniSAr, and GPT-4. The results highlight a "Generalization Myth": models that achieve over 80% accuracy on general benchmarks like Spider see their performance plummet to as low as 0-10% on BookSQL without domain-specific fine-tuning.

Performance comparison showing the significant accuracy drop when models trained on Spider are tested on BookSQL.

Key Findings:

  • The Complexity Gap: While models achieved near 100% accuracy on "Easy" queries, performance crashed to 12-22% on "Hard" queries involving nested logic.
  • Time-Based Filtering: Handling filters like "last quarter" or "fiscal year to date" proved to be a major hurdle. Models frequently hallucinated or misapplied SQL functions like strftime and date.
  • Column Confusion: Models often confused similar-looking columns, such as mistakenly using product_service when the query required an account name from the Chart of Accounts.
  • Specialized vs. General Models: RESDSQL was the top fine-tuned performer with 51.5% Exact Match Accuracy (EMA). In contrast, GPT-4 (using Dynamic Few-Shot prompting) achieved a lower EMA of 47.5% but a higher Execution Accuracy (67.2%), suggesting it often generates functional, if not exact, SQL.

Conclusion and Future Work

BookSQL exposes the limitations of current Text-to-SQL models in specialized domains. Future work must address "Value Encoding"—the ability to identify specific strings or IDs for WHERE clauses—and explore multi-step reasoning approaches. Additionally, there is a clear need for pre-training tasks that help models understand the inherent relationships between tables in complex financial schemas before they are tasked with natural language interpretation.

Summary updated

BibTeX
@inproceedings{kumar2024booksql,
  author = {Rahul Kumar and Amar Raja Dibbu and Shrutendra Harsola and Vignesh Subrahmaniam and Ashutosh Modi},
  title = {{BookSQL: A Large Scale Text-to-SQL Dataset for Accounting Domain}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-long.28},
}
Figure