Error Detection for Text-to-SQL Semantic Parsing

Shijie Chen, Ziru Chen, Huan Sun, Yu Su

Abstract

Modern Text-to-SQL parsers frequently exhibit overconfidence, producing syntactically valid but semantically incorrect queries that execution engines fail to catch. We present a parser-independent error detection framework, CodeBERT+GAT, designed to identify these "silent" failures. By leveraging pre-trained language models alongside Graph Attention Networks (GATs) to capture structural logic, our approach significantly outperforms traditional uncertainty metrics. Evaluation across multiple base parsers and datasets demonstrates improved execution accuracy and reduced user interaction costs in natural language database interfaces.

Introduction

The translation of natural language questions into executable SQL queries is a cornerstone of accessible data analytics. However, the "trustworthiness" of these systems remains a significant barrier to production deployment. Deep-learning-based parsers are notoriously overconfident; they may generate a query that executes perfectly but returns incorrect data due to a misunderstanding of user intent.

Standard error detection often relies on "parser-dependent" metrics, such as the probability scores the parser itself assigns to a query. These metrics are ineffective when the parser itself is overconfident. This research introduces a "parser-independent" detector—a standalone module that evaluates the alignment between a question and a generated SQL query, regardless of the underlying parser architecture.

Methodology: The CodeBERT+GAT Architecture

The proposed model utilizes a hybrid architecture to bridge the gap between natural language and structured query logic.

The CodeBERT+GAT architecture combines contextual embeddings from CodeBERT with structural graph representations via GAT.
  1. Contextual Embeddings (CodeBERT): The model uses CodeBERT, a transformer pre-trained on both natural language and code, to generate initial embeddings for the input question and the candidate SQL query.
  2. Structural Enhancement (GAT): To better capture logical dependencies, Graph Attention Networks (GAT) are employed. For questions, dependency and constituency parse trees are merged into a unified graph. For SQL, Abstract Syntax Trees (ASTs) are extracted and simplified to highlight core logic.
  3. Cross-Domain Error Training: To ensure generalization, the model is trained on realistic errors collected by running "weak" parsers on databases unseen during their own training. This forces the detector to learn general patterns of semantic failure rather than memorizing specific schema mappings.

Experimental Setup

The model was evaluated using the Spider benchmark, a large-scale cross-domain Text-to-SQL dataset, and KaggleDBQA for zero-shot testing on real-world web databases. The detector was tested against three distinct parser architectures:

  • SmBoP: A bottom-up parser.
  • BRIDGE v2: A sequence-to-sequence model.
  • NatSQL: A grammar-based approach.

Key Results and Discussion

The CodeBERT+GAT model consistently outperformed baseline uncertainty metrics, such as dropout-based uncertainty and raw probability scores, across all tested parsers.

Performance comparison of different error detection methods across SmBoP, BRIDGE v2, and NatSQL parsers, showing precision and interaction accuracy.

Structural Reasoning

The inclusion of GAT provided the most significant performance gains on "hard" and "extra hard" complexity levels. This confirms that while transformers excel at sequence modeling, explicit structural representations are crucial for complex logical reasoning in SQL.

Interactive Efficiency and Re-ranking

In simulated interactive environments, the detector triggered user clarifications more accurately, reducing required interactions by 3.4% to 33% while maintaining a target system accuracy of 95%. Furthermore, using the model to re-rank the top-k queries generated by BRIDGE v2 and NatSQL led to measurable improvements in final execution accuracy.

Generalization and Schema Blindness

Interestingly, the authors found that excluding database schema information (table and column names) from the detector's input actually improved generalization. This suggests that the model avoids overfitting to specific schema links, focusing instead on the fundamental semantic mapping between the question and the SQL logic.

Conclusion and Future Work

CodeBERT+GAT provides a robust, plug-and-play solution for enhancing the reliability of Text-to-SQL systems. While the current model demonstrates strong cross-domain performance, future work will explore better ways to integrate schema information to catch column-specific errors without sacrificing generalization. Additionally, the use of synthetic data generation could further expand the diversity of training sets for error detection.

Summary updated

BibTeX
@inproceedings{chen2023error,
  author = {Shijie Chen and Ziru Chen and Huan Sun and Yu Su},
  title = {{Error Detection for Text-to-SQL Semantic Parsing}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.785},
}
Figure