AI Agents Generate SQL, Redesigning Analytics Infrastructure
Engineer Peihao Yuan presented a disaster recovery data analysis workflow where AI agents automatically generate SQL and Python code, with DuckDB handling computations. The design achieves reproducibility and reliability by clearly separating the parts handled by AI from deterministic calculations, and also presents four indicators to determine whether an embedded engine is sufficient or a cloud-based infrastructure is necessary.

A workflow is being proposed in which AI agents automatically generate SQL and Python code and perform data analysis combined with a lightweight query engine. In this architecture presented by engineer Peihao Yuan, AI takes on the "thinking" part while computation processing is clearly delegated to a separate dedicated engine. Notably, the design philosophy is concretely demonstrated using disaster recovery analytics scenarios (business continuity after system failures) as the subject matter.
In data analysis using AI, approaches where "AI directly provides answers" have been widely attempted. However, this method has the drawback that answers may change each time, making it unsuitable for business purposes where auditing and reproducibility are required. What this proposal emphasizes is "reproducibility" and "deterministic computation"—structures that always produce the same results for identical inputs. The approach is based on the idea that by clearly separating parts where AI's variability is tolerable from computation parts where it is not, a highly reliable analytics foundation can be built.
The specific architecture presented is one where AI agents generate SQL statements or Python code, and DuckDB (a lightweight embedded analytical database) executes those queries. Data is stored in Parquet format (a columnar, efficient file format), and query results are interpreted and summarized by AI agents. In this configuration, the code generated by AI itself remains as logs, making it possible to reproduce the same analysis later or track who posed which questions.
The proposal also presents four indicators for determining the choice of analytics infrastructure. These are signals to determine whether DuckDB alone is sufficient or whether a larger-scale managed lakehouse (a data accumulation and analytics platform managed in the cloud) is necessary. Data scale, team size, governance requirements, and the need for real-time performance are likely to be the judgment criteria. By presenting these judgment criteria, the proposal offers a path for establishing practical analytics environments while avoiding excessive infrastructure investment.
The background for this architecture gaining attention lies in the fact that as real-world applications of AI agents accelerate, the question of "how to verify results generated by AI" becomes increasingly important. A structure where AI writes code and a separate system executes that code serves as a design that makes it easier for humans to verify AI outputs, and has the potential to become one of the standard forms of business AI systems going forward.
From the perspective of reproducible analysis, applications in scenarios where records and accountability are required—such as compliance and incident response—are anticipated. The mechanism where queries generated by AI remain as evidence makes it possible to explain "why the analysis produced these results" later, providing transparency. From the viewpoint of reliability design when integrating AI into business processes, this workflow can serve as a practical reference model.
A key point to watch going forward is whether this separation design of "AI as interface, computation as dedicated engine" expands to broader industries and use cases. How to determine the boundary between the scope that can be handled by embedded engines like DuckDB and what requires large-scale cloud infrastructure is an important consideration that serves as a guide for practitioners when thinking about the tradeoff between data utilization costs and system complexity.
This article is an original work independently written and edited by the AI issue editorial team based on factual reporting. © AI issue. Unauthorized reproduction, redistribution, or use for AI training is prohibited.