UCS - SQL : Uniting Content and Structure for Enhanced Semantic Bridging In Text-to- SQL (2025)

Abstract: With the rapid advancement of large language models (LLMs), recent researchers have increasingly focused on the superior capabilities of LLMs in text/code understanding and generation to tackle text-to-SQL tasks. Traditional approaches adopt schema linking to first eliminate redundant tables and columns and prompt LLMs for SQL generation. However, they often struggle with accurately identifying corresponding tables and columns, due to discrepancies in naming conventions between natural language questions (NL) and database schemas. Besides, existing methods overlook the challenge of effectively transforming structure information from NL into SQL. To address these limitations, we introduce UCS-SQL, a novel text-to-SQL framework, uniting both content and structure pipes to bridge the gap between NL and SQL. Specifically, the content pipe focuses on identifying key content within the original content, while the structure pipe is dedicated to transforming the linguistic structure from NL to SQL. Additionally, we strategically selects few-shot examples by considering both the SQL Skeleton and Question Expression (SS-QE selection method), thus providing targeted examples for SQL generation. Experimental results on BIRD and Spider demonstrate the effectiveness of our UCS-SQL framework.

## introduction text-to-sql is the task of translating natural language queries into sql statements, which has garnered extensive research attention and practical application in database querying @xcite . based on the representations encoded by bert-style pre-trained models @xcite , abstract syntax trees @xcite @xcite and predefined query sketches @xcite are implemented for query decoding. further, some works extract generalized question-to-sql patterns by training encoder-decoder models on text-to-sql corpora @xcite @xcite . inspired by the powerful capabilities of large language model (llm) in handling complex reasoning @xcite , the recent studies have achieved promising results by developing prompt engineering for llms @xcite @xcite . for example, implementing schema linking to eliminate redundant information, followed by guiding llms to generate sql queries through in-context learning processes. the forefront researches adhere to the retrievethen-generate paradigm. mcs-sql @xcite exploits llms' extensive sample libraries for schema linking and employs multiple prompts to elicit diverse llm responses. rsl-sql @xcite integrates bidirectional schema linking, contextual information augmentation, binary selection strategy, and multi-turn self-correction to achieve state-of-the-art performance. however, the traditional retrieve-then-generate pipeline in textto-sql tasks still confronts two challenges. (1) existing methods struggle with precise schema linking and identifier selection (e.g., column and table names) due to terminological mismatches between colloquial questions and schema identifiers. in this paper, we introduce ucs-sql , a threestage text-to-sql framework that integrates content and structure pipes to enhance semantic bridging. the content pipe extracts key information from the raw question, while the structure pipe converts nl into sql syntax. figure 2 illustrates the ucs-sql framework. in the question stage, a llm extracts content and structure information from the raw question. then in the transitional stage, we prompt the llm to transform them into sql identifiers and functions. the content pipe integrates evidence and foreign keys to refine content information and performs bi-directional schema link-ing to identify relevant schema identifiers, while the structure pipe infers sql functions based on the extracted structure information. finally, in the sql stage, we construct a sql skeleton using the inferred functions and fill it with the identified identifiers to generate the final query. additionally, we develop an ss-qe algorithm to select few-shot examples for the llm, considering similarities in both sql skeletons and question expressions. comprehensive evaluations on the bird and spider datasets demonstrate that ucs-sql outperforms several baselines in terms of valid efficiency score (ves) and execution accuracy (ex) across different difficulty levels. it achieves top-2 performance on all evaluation metrics on bird and top-3 performance on spider. to summarize, our contributions are as follows: ## problem definition text-to-sql is the task of converting a natural language question q into a correct sql query y . the database can be represented as @xmath0, t 2 ...t m }, m is the number of tables in the database. for @xmath1, c 2 ...c n }, c i refers to columns in table t , n is the number of columns in the table. when dealing with complex database values, we can use external knowledge evidence k to support our model understand the inner relationship between question and database. the process could be formulated as follows: ## implementation details we use a single tesla v100 gpu with 32 gibs of memory on a server to restore intermediate data and execute ss-qe example selection algorithm, the retrieving time is about 3∼6 seconds for each sample. all the experiments utilize gpt-4-turbo, the context window is 128000, the temperature is set to 0.1. we enable five threads to run ucs-sql ## related work large language models (llms) have demonstrated significant advancements in various natural language processing (nlp) tasks @xcite @xcite @xcite @xcite . some researchers have leveraged llms in text-to-sql tasks to further enhance performance. a critical aspect of this approach is the design and utilization of prompts, which directly influence the accuracy of sql generation by guiding llms effectively. for example, some methods @xcite try to improve the inference capabilities of llms using chain-of-thought prompting, including both the original chain-of-thought prompt and the least-to-most prompt. further, a comprehensive analysis @xcite of the impact of prompt construction across various settings in text-to-sql tasks is studied. dail-sql @xcite considers both questions and sql queries to select few-shot examples, adopts an example organization strategy to balance quality and quantity, and utilizes code representation prompting for question representation. besides, c3-sql @xcite and din-sql (pourreza and rafiei, 2023) have introduced innovative frameworks for database simplification, query decomposition, and prompt engineering. researchers introduce schema linking to identify the database tables and columns associated with natural language queries and have proposed complex and integrated prompting engineering methods @xcite . mac-sql @xcite ) centered on multi-agent collaboration can be utilized for more intricate data scenarios and a broader spectrum of error types for detection and correction. ta-sql @xcite and codes @xcite introduce strategies to mitigate hallucinations in llm-based sql generation. chess @xcite enables more accurate schema linking by retrieving relevant information from database catalogs and database values. another approach, mag-sql @xcite ) features a multi-agent generative approach with soft schema linking and iterative sub-sql refinement. msc-sql @xcite mitigates the performance gap of smaller open-source models by sampling and comparing multiple sql query results. rsl-sql combines bidirectional schema linking, contextual information augmentation, binary selection strategy, and multiturn self-correction to achieve an efficient framework. but previous works are difficult to accurately retrieve the correct identifiers content from the schema and often overlook the understanding and reasoning of structure hints during sql generation. ## conclusion in this paper, we propose ucs-sql, a three-stage text-to-sql framework integrating a content pipe for key content extraction and a structure pipe for linguistic structure transformation. through the three stages of ucl-sql, the content and structure pipes jointly accomplish the generation from nl question to sql query. then, we introduce the ss-qe example selection method, which selects appropriate few-shot examples for target questions by taking into account the similarities in both sql structure and question expression. the experimental results on the bird and spider datasets demonstrate that ucs-sql achieves superior performance in ex and ves, and substantiate the effectiveness of both the content and structure pipes. the integration of content and structure pipes will guide future research to jointly consider the text-to-sql generation process from both dimensions.