SQL-to-Text Generation with Weighted-AST Few-Shot Prompting

πŸ“… 2025-11-17
πŸ“ˆ Citations: 0
✨ Influential: 0
πŸ“„ PDF
πŸ€– AI Summary
SQL-to-text generation aims to enhance non-technical users’ comprehension of database queries, yet existing approaches suffer from insufficient logical fidelity due to semantic drift and lexical diversity. To address this, we propose the AST-Guided Weighted Retrieval (AWR) framework: first, SQL queries are parsed into Abstract Syntax Trees (ASTs) to explicitly encode structural semantics; second, a weighted AST similarity retrieval mechanism is introduced, dynamically learning node importance weights to enable structure-aware few-shot prompting; finally, a large language model generates natural-language descriptions conditioned on retrieved exemplars. Evaluated on Spider, SParC, and CoSQL benchmarks, AWR achieves up to 17.24% absolute improvement in exact-match accuracy. Human evaluation confirms significant gains in semantic consistency and descriptive fluency over baselines, while maintaining efficient inference.

Technology Category

Application Category

πŸ“ Abstract
SQL-to-Text generation aims at translating structured SQL queries into natural language descriptions, thereby facilitating comprehension of complex database operations for non-technical users. Although large language models (LLMs) have recently demonstrated promising results, current methods often fail to maintain the exact semantics of SQL queries, particularly when there are multiple possible correct phrasings. To address this problem, our work proposes Weighted-AST retrieval with prompting, an architecture that integrates structural query representations and LLM prompting. This method retrieves semantically relevant examples as few-shot prompts using a similarity metric based on an Abstract Syntax Tree (AST) with learned feature weights. Our structure-aware prompting technique ensures that generated descriptions are both fluent and faithful to the original query logic. Numerous experiments on three benchmark datasets - Spider, SParC, and CoSQL show that our method outperforms the current baselines by up to +17.24% in execution Accuracy (EX), performs superior in Exact Match (EM) and provides more consistent semantic fidelity when evaluated by humans, all while preserving competitive runtime performance. These results demonstrate that Weighted-AST prompting is a scalable and effective method for deriving natural language explanations from structured database queries.
Problem

Research questions and friction points this paper is trying to address.

Translating SQL queries into natural language for non-technical users
Maintaining exact SQL semantics across multiple phrasing variations
Improving semantic fidelity in SQL-to-text generation using structure-aware methods
Innovation

Methods, ideas, or system contributions that make the work stand out.

Weighted-AST retrieval for semantic example selection
Structure-aware prompting with learned feature weights
Integrating Abstract Syntax Trees with LLM few-shot learning
πŸ”Ž Similar Papers
No similar papers found.
S
Sriom Chakrabarti
Aalborg University, Denmark
C
Chuangtao Ma
Aalborg University, Denmark
A
Arijit Khan
Bowling Green State University, USA
Sebastian Link
Sebastian Link
Professor of Computer Science, The University of Auckland
Artifical IntelligenceDatabasesDiscrete MathsLogic