arXiv(opens in a new tab)cs.AIAug 2026Cited by 2 papers on PaperVantage

Manuscript Offprint

arXiv:2608.29345

BIRD-History: A Benchmark for History-Driven Text-to-SQL with Fine-Grained Knowledge Annotations

Yunfan Zhou, Qiming Shi, Yizhou Yang, Di Weng, Yingcai Wu

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

While recent Large Language Model (LLM)-based text-to-SQL systems achieve impressive performance on standard benchmarks, they struggle when user queries implicitly rely on domain-specific knowledge, such as business logic, data conventions, and analytical practices, that is neither captured by the schema nor explicitly stated in the natural language question. Historical SQL query logs offer a valuable source of such knowledge, yet existing benchmarks do not adequately support evaluation of history-driven approaches. To address this gap, we introduce BIRD-History, a benchmark consisting of 1,393 tasks across 11 databases, designed to evaluate text-to-SQL systems' ability to ground underspecified natural language questions using historical SQL scripts. Each task is annotated with ground-truth labels specifying which historical queries contain relevant knowledge and which SQL clauses encode it, enabling systematic evaluation of both retrieval effectiveness and knowledge utilization. We further introduce a plug-in retriever that extracts relevant knowledge from historical logs, seamlessly enhancing existing few-shot text-to-SQL pipelines without architectural modifications. Experiments demonstrate consistent improvements across four text-to-SQL systems, highlighting the value of leveraging historical query logs for handling underspecified queries. Dataset and code are open-sourced on https://github.com/zjuidg/BIRD-History.

1 Introduction

Text-to-SQL, which converts natural language questions into database queries, has emerged as a powerful tool for democratizing data exploration and analysis (Liu et al., 2025b; Hong et al., 2025; Katsogiannis-Meimarakis and Koutrika, 2023). Recent text-to-SQL approaches (Li et al., 2025a; Xie et al., 2025; Liu et al., 2025a; Wang et al., 2025; Pourreza and Rafiei, 2023) utilizing Large

Figure

Figure 1: A text-to-SQL example from the BIRD dataset involving external knowledge.

Language Models (LLMs) have driven remarkable progress, with state-of-the-art systems achieving over 90% accuracy on the Spider (Yu et al., 2018) benchmark and 80% on the more challenging BIRD (Li et al., 2023b) benchmark.

Current text-to-SQL approaches primarily rely on schema linking to match database elements with natural language tokens based on few-shot learning (Pourreza and Rafiei, 2023) or dynamic retrieval (Xie et al., 2025; Gao et al., 2024; Li et al., 2024). However, while these techniques effectively learn common query patterns across domains, they often struggle when user queries implicitly rely on nuanced domain-specific knowledge, such as business logic, data conventions, and analytical practices, that is neither captured by the schema nor explicitly stated in the natural language question. For instance, in a European football match database, asking for the league with “the most matches end in a draw” requires understanding that draws are identified by comparing home and away team goals, and that “2016 season” corresponds to the value “2015/2016” in the database (Figure 1). Such domain-specific knowledge is hard to infer from the schema alone and varies significantly across different domains. While explicit knowledge bases offer one solution to capturing domain-specific information, they require substantial manual effort from domain experts to construct and maintain, particularly as database schemas and business logic evolve over time.

Recent work has recognized historical SQL queries as a valuable knowledge source for text-to-SQL generation. TailorSQL (Vaidya et al., 2025) shows that past query workloads implicitly encode domain-specific information, such as common join paths and column semantics, that is not apparent from the schema alone. However, existing benchmarks do not adequately support evaluation of such history-driven approaches, as they either lack historical query contexts or do not provide ground-truth labels linking queries to the specific historical SQL fragments required for their generation.

To address this gap, we introduce BIRD-History, a benchmark for evaluating text-to-SQL systems' ability to ground underspecified natural language queries using historical SQL scripts. BIRD-History is built upon the BIRD dataset (Li et al., 2023b) and consists of 1,393 tasks across 11 databases. The construction of BIRD-History follows a hybrid approach combining LLM-based generation under carefully designed constraints, LLM-as-a-judge refinement, and human expert cross-validation. For each task, a text-to-SQL system is provided with three types of inputs: the development set of the original BIRD dataset as historical SQL queries, database schemas, and an underspecified natural language question. Crucially, each task is annotated with ground-truth labels specifying which historical queries contain knowledge relevant to the target query, along with the specific SQL clauses (e.g., WHERE, LIMIT, JOIN) that encode this knowledge. These fine-grained annotations enable systematic evaluation of both retrieval effectiveness (i.e., how well systems identify relevant historical queries) and knowledge utilization (i.e., whether systems extract and apply the correct SQL fragments for generation).

Based on BIRD-History, we further propose a plug-in retriever that extracts fine-grained knowledge fragments from historical SQL queries to improve text-to-SQL generation. The retriever operates in two stages: offline and online. In the offline stage, it parses historical SQL queries into code fragments corresponding to five types of external knowledge, including calculation, condition, relation, dimension, and output. These code fragments are then translated into natural language forms using LLMs to facilitate effective retrieval. In the online stage, given a user question, the retriever first broadly recalls relevant knowledge based on semantic similarity. The recalled knowledge is subsequently refined through LLM-based reranking and filtering to ensure precision. The retrieval results can be seamlessly integrated into existing dynamic few-shot text-to-SQL pipelines without requiring modifications to their prompt templates. Empirical evaluation on BIRD-History demonstrates consistent improvements across four existing text-to-SQL systems.

In summary, we make three key contributions:

• We present BIRD-History, a benchmark specifically designed to evaluate text-to-SQL systems’ capability to ground external knowledge from historical query logs.

• We introduce a plug-in retriever that extracts and retrieves fine-grained external knowledge from historical SQL queries.

• We demonstrate through experiments that our approach outperforms prior retrieval methods for text-to-SQL generation.

References (5)

  • used_ori_sqls
  • This is because the task you create is not simply the combination of components, but a new SQL query that reuses the knowledge/logic behind these components
  • Usually you can find them in FROM-JOIN-ON statement
  • Usually you can find them in SELECT statement
  • [A phrase or word that serves as a modifier]