| Issue |
A&A
Volume 711, July 2026
|
|
|---|---|---|
| Article Number | A302 | |
| Number of page(s) | 21 | |
| Section | Numerical methods and codes | |
| DOI | https://doi.org/10.1051/0004-6361/202558221 | |
| Published online | 24 July 2026 | |
Querying an astronomical database using large language models: the ALeRCE text-to-SQL system
1
Department of Electrical Engineering, University of Chile,
Av. Tupper
2007,
Santiago,
Chile
2
Millennium Institute of Astrophysics (MAS),
Nuncio Monseñor Sótero Sanz 100, Providencia,
Santiago,
Chile
3
Data and Artificial Intelligence Initiative (ID&IA), Universidad de Chile,
Chile
4
Center for Mathematical Modeling, Universidad de Chile,
Beauchef 851, North building, 7th floor,
Santiago
8320000,
Chile
5
Departamento de Astronomía, Universidad de Chile,
Casilla 36D,
Santiago,
Chile
6
Department of Computer Science,
Universidad de Conceptión Edmundo Larenas 219,
Conceptión,
Chile
7
Center for Data and Artificial Intelligence, Universidad de Conceptión,
Edmundo Larenas 310,
Conceptión,
Chile
8
Heidelberg Institute for Theoretical Studies,
Heidelberg, Baden-Württemberg,
Germany
9
Instituto de Alta Investigatión, Universidad de Tarapacá,
Casilla 7D,
Arica
1010000,
Chile
10
European Southern Observatory,
Karl-Schwarzschild-Strasse 2,
85748
Garching bei München,
Germany
11
Instituto de Astrofísica, Facultad de Física, Pontificia Universidad Católica de Chile,
Casilla 306,
Santiago 22,
Chile
12
Centro de Astroingeniería, Pontificia Universidad Católica de Chile,
Av. Vicuña Mackenna 4860,
7820436
Macul,
Santiago,
Chile
13
Instituto de Estudios Astrofísicos, Facultad de Ingeniería y Ciencias, Universidad Diego Portales,
Av. Ejército Libertador 441,
Santiago,
Chile
14
Centro Interdisciplinario de Data Science, Facultad de Ingenieria y Ciencias, Universidad Diego Portales,
Av. Ejército Libertador 441,
Santiago,
Chile
★ Corresponding author: This email address is being protected from spambots. You need JavaScript enabled to view it.
Received:
22
November
2025
Accepted:
11
June
2026
Abstract
We developed a text-to-structured query language (SQL) system based on large language models (LLMs) using in-context learning and applied it to the Automatic Learning for the Rapid Classification of Events (ALeRCE) astronomical database. ALeRCE is a community broker for the Zwicky Transient Facility and the Vera C. Rubin Observatory. The system enables users to query the database in natural language (NL) and generates executable SQL queries. To develop and evaluate the system, we constructed a set of 110 NL-SQL pairs. We propose a step-by-step generation framework comprising four modules: schema linking, query classification, prompt decomposition, and self-correction. The performance of 13 LLMs was evaluated using in-context learning and prompt engineering techniques. Text-to-SQL performance was assessed using the perfect-match (PM) rate for row identifiers (e.g., object identifiers) and column identifiers (i.e., column names). The proposed step-by-step framework consistently outperforms a direct-inference baseline, while the self-correction module consistently reduces execution errors. For Claude Opus 4.6, PM performance on row (column) identifiers is high for simple queries, reaching 0.97 (0.94), and decreases with query complexity to 0.44 (0.72) for medium queries and 0.59 (0.49) for hard queries. Among the 13 models evaluated, the best-performing LLMs for the text-to-SQL task are Claude Opus 4.6, Gemini 2.5 Pro, Gemini 3 Flash, and GPT-5.2-Codex.
Key words: astronomical databases: miscellaneous / catalogs / surveys
© The Authors 2026
Open Access article, published by EDP Sciences, under the terms of the Creative Commons Attribution License (https://creativecommons.org/licenses/by/4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.
This article is published in open access under the Subscribe to Open model. This email address is being protected from spambots. You need JavaScript enabled to view it. to support open access publication.
Current usage metrics show cumulative count of Article Views (full-text article views including HTML views, PDF and ePub downloads, according to the available data) and Abstracts Views on Vision4Press platform.
Data correspond to usage on the plateform after 2015. The current usage metrics is available 48-96 hours after online publication and is updated daily on week days.
Initial download of the metrics may take a while.