TL;DR
This paper introduces SQLMorpher, a novel framework that uses Large Language Models (LLMs) to automatically transform data between different schemas, specifically for building energy data. By leveraging LLMs' coding and reasoning abilities, SQLMorpher achieves a remarkable 96% accuracy on a new benchmark of 105 real-world data transformation problems, significantly outperforming existing methods.
What Problem Does This Paper Address?
Integrating data from diverse sources is crucial for many applications, especially in sectors like building energy management, where data from various systems needs to be harmonized for effective analysis and control. However, existing automatic data transformation tools struggle with this task due to several limitations:
- Lack of Domain Knowledge Integration: They offer no easy way for domain experts to inject their valuable knowledge into the transformation process.
- High Training Data Overhead: They often require extensive labeled data, which is costly and time-consuming to collect.
- Difficulty with Complex Schema Changes: Handling intricate schema transformations, such as attribute renaming, aggregation, and pivoting, proves challenging, leading to lower accuracy.
The authors highlight that the building energy sector, in particular, presents complex data transformation needs that current tools fail to meet.
Methods
The core of the proposed solution is SQLMorpher, an LLM-based framework designed to generate SQL code for data transformation. It tackles the problem in two main steps:
- Text-to-SQL Generation: SQLMorpher uses LLMs to generate SQL queries that map data from source schemas to target schemas. This step focuses on schema mapping, avoiding the need to upload entire datasets.
- SQL Execution: The generated SQL code is then executed in a sandbox environment to transform the data.
Key novel components of SQLMorpher include:
- Prompt Generator: This component creates a unified prompt template that can integrate various optional information, such as domain-specific knowledge, schema change hints, and historical prompt examples from external databases. This allows for flexible and context-aware prompt construction.
- Iterative Prompt Optimization: SQLMorpher automatically detects flaws in the LLM's generated SQL code or the resulting transformed data. It then augments the prompt with these identified errors and re-submits it to the LLM, iteratively refining the prompt until a correct transformation is achieved or a maximum number of iterations is reached.
Datasets
The paper introduces a new benchmark dataset specifically for building energy data transformation. This benchmark comprises 105 real-world problems collected from 21 energy companies in the United States, divided into 15 groups. Each case includes source and target schemas, domain-specific explanations, schema change hints, and ground truth transformation queries.
Additionally, the authors evaluated their approach on:
- A commercial benchmark used by the Auto-Pipeline baseline (16 cases).
- Four COVID-19 data transformation cases from a publicly available repository.
Key Insights and Ideas
- LLMs are Powerful for Data Transformation: The study demonstrates that LLMs, with their advanced reasoning and coding capabilities, are highly effective for complex data transformation tasks, even in specialized domains like building energy.
- Domain Knowledge is Crucial: Providing domain-specific information, especially schema change hints (e.g., "use aggregation," "map attribute X to Y"), significantly boosts the accuracy of LLM-generated SQL, far more than just providing schema descriptions.
- Iterative Refinement Works: The iterative prompt optimization mechanism is vital for handling complex cases and improving accuracy, especially when initial prompts are not perfect.
- Zero-Shot Learning is Effective: SQLMorpher can achieve high accuracy even without extensive training examples, relying on the LLM's pre-trained knowledge. Few-shot learning can further improve performance on challenging cases.
- SQL is a Good Target Language: The declarative nature of SQL makes it a suitable target for LLM-generated data transformation queries.
Key Results
- SQLMorpher achieved an impressive 96% execution accuracy on the 105 real-world building energy data transformation problems in their newly created benchmark.
- When compared to the Auto-Pipeline tool on its commercial benchmark, SQLMorpher achieved 81% accuracy without domain knowledge and 94% with domain knowledge, significantly outperforming Auto-Pipeline's reported accuracy of below 70%.
- The iterative optimization process was beneficial for 9.5% of cases when using the best prompt configuration (Prompt-3).
- The system demonstrated generalization capabilities on COVID-19 data and other benchmarks.
Limitations and Future Work
- Validation Complexity: While the experimental environment uses manually prepared ground truth queries for validation, real-world production environments face challenges in automatically measuring the quality of transformed data. The authors leave the development of automatic quality measurement (e.g., unit tests, self-consistency checks) for future work.
- Prompt Size Limitations: The authors note that for very complex cases with many attributes, the prompt size can become a limitation, especially for certain LLM APIs (e.g., ChatGPT-3.5-turbo-16K).
- Future Work: The authors plan to design quality control mechanisms for SQLMorpher to further reduce the need for human validation in production environments. They also aim to explore more advanced techniques for integrating domain knowledge and optimizing prompts.
Summary updated