F in S tat2 SQL : A T ext2 SQL Pipeline for Financial Statement Analysis (2025)

Abstract: Despite recent advances in LLMs, Text2SQL remains challenging for complex, domain-specific queries such as finance, where database designs and reporting standards vary widely. We introduce FinStat2SQL, a lightweight pipeline enabling natural language queries over financial statements, tailored to local standards like VAS. Our multi-agent setup combines large and small language models for entity extraction, SQL generation, and self-correction, and includes a fully automatic pipeline for synthetic data generation. Leveraging this synthetic data, we fine-tuned a 7B model that achieves 61.33% accuracy with sub-4s latency on consumer hardware, outperforming GPT-4o-mini on SQL generation. FinStat2SQL provides a scalable, cost-efficient solution for financial analysis. We made our source code publicly available at: https://github.com/hung20gg/chatbot_financial_statement.

## introduction generating accurate sql from users' natural language questions (text2sql) is a long-standing challenge @xcite , especially in the scenario that both the database system and user queries are growing more complex. for years, many attempts have been carried out @xcite , introducing more sophisticated methods: from deep neural networks @xcite to generative language models @xcite . the results of language models (lms) are very promising, however, many challenges persist when dealing with domain-specific tasks, which require further studies and refinement into each task. database systems continue to grow rapidly and support for more languages becomes increasingly necessary, the potential applications of text2sql are broad, particularly in financial database systems, where structured querying via natural language can greatly enhance accessibility and efficiency. applications of text2sql are wide, for example, in-tegrating into systems such as financial reporting automation, customer support chatbots, regulatory monitoring, as well as healthcare record querying, academic research databases, supply chain tracking, hr analytics @xcite . financial reports are essential for communicating a company's financial health and informing the decisions of investors, regulators, and analysts. however, manual analysis is often time-consuming, prone to human error, and inefficient for professionals who require fast, accurate insights from large volumes of financial data. while many companies globally follow the international financial reporting standards (ifrs) issued by the international accounting standards board (iasb) @xcite , national adaptations can vary significantly @xcite . for instance, @xcite highlights that vietnam accounting standards (vas) only partially converge with ifrs, resulting in structural and interpretational differences. this diversity adds complexity to querying financial indicators across jurisdictions. to address these challenges, many text2sql techniques have gained traction as a promising solution for automating and streamlining financial analysis @xcite . in this research, we design a pipeline for generating sql from financial statistics (figure 1 ), and evaluate the sql query generation capabilities of various lms within the context of the vietnamese companies financial statement system. our study encompasses both large language models (llms) and small language models (slms), assessing their effectiveness in translating natural language questions into executable sql queries. we particularly focus on slms since they are increasingly trending in agent design due to being more economical and flexible, while not requiring the full capacity of llms for many domain-specific tasks @xcite . in addition, we propose a synthetic data generation pipeline for training slms and benchmark them with multiple training strategies to determine which approaches yield the best performance for domain-specific tasks. ## literature review in this section, we outline the challenges of querying financial indexes, provide a brief overview of recent advances in text2sql methods, and present key techniques for tuning lms. ## synthetic data to train the lms effectively for financial analysis, we created a large-scale synthetic questionanswer dataset focused on exploring, interpreting, and analyzing financial statements. inspired by @xcite , the dataset was generated through an automated pipeline designed to cover a broad range of tasks, including fundamental, technical, and comparative financial analysis. we used gemini-2.0-flash-thinking-exp-01-21 2 and gpt-4o mini 3 as the main generators for this synthetic data. the example of golden query and result is represented at appendix a, and the synthetic pipeline is in figure 2 . ## finstat2sql pipeline in this section, we introduce finstat2sql, a pipeline that converts noisy financial queries into accurate sql using entity extraction, code generation, and self-correction (figure 1 ). the pipeline is specifically adapted to the structure of vas, which differs from ifrs, ensuring accurate handling of local financial data. for reference, we include the prompt template of each component in the pipeline in appendix c 5.1 text2sql pipeline entity extraction. the entity extraction step uses llms to identify key elements in user queries for group score question p95 original non-performing loan (npl) ratio of the banking sector in 2023 0.8496 for the banking sector listed on hose, compare the ratio of non-performing loans (npls) to total loans for the year 2023. how does this ratio vary across different banks, and what factors might explain the differences? mean original bad debt ratio of banking industry from q1 2020 to q1 2024 0.7800 analyze the trend of the non-performing loan ratio for companies in the 'banking' industry listed on the vn30 index from 2020 to q3 2024. ## experiment in general, our finstat2sql is a fine-tuned version of qwen 2.5 coder for each model size, integrated with our proposed pipeline for enhanced performance.