Teaching SQL with an Agentic LLM: A Fifteen-Category Hallucination Taxonomy and Mitigation Strategy, Illustrated with Claude Sonnet 5

Students increasingly use large language models (LLMs) to translate natural-language requests into SQL, yet these models hallucinate: they return queries, numbers, explanations or assurances unsupported by the schema, data, or request, often in a form that executes without error. This paper proposes a teaching instrument for a first course on relational databases, designed to let students experience, recognize and prevent such failures; its contribution is conceptual and illustrative. This paper proposes a teaching instrument for a first course on relational databases that lets students experience, recognize, and prevent such failures. Its core is a taxonomy of fifteen hallucination categories that is coarse enough to serve as a classroom checklist, identified through an expert-driven process (the text-to-SQL literature and 27 years of teaching experience) and illustrated on a five-table PostgreSQL schema through constructed baseline outputs that the instructor can use to open a classroom discussion of each failure. Each category is paired with a two-layer mitigation: a context pack of standing rules and seven reference files, stored once in a Claude Project, and an agentic execute–observe–correct loop in which the assistant runs rule-prescribed checks against a live database before answering. Each countermeasure is assigned to the instructor, the loop, or the user. Nine categories have a counterpart in prior text-to-SQL taxonomies, two lack a dedicated one, and four concern the answer returned to the user rather than the query, thereby escaping static benchmark-based evaluation. The workflow is free for students. The effectiveness and generalizability of the mitigation have not yet been systematically validated; frequency and classroom effectiveness are left to future work.

Authors

Publication Details

Journal
Applied Sciences
Published
2026-11-23
DOI
https://doi.org/10.3390/app162311607
Primary Topic
Teaching and Learning Programming
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
article

Teaching SQL with an Agentic LLM: A Fifteen-Category Hallucination Taxonomy and Mitigation Strategy, Illustrated with Claude Sonnet 5

Paolino Di Felice
3 links
Applied Sciences
Teaching and Learning Programming
article

Teaching SQL with an Agentic LLM: A Fifteen-Category Hallucination Taxonomy and Mitigation Strategy, Illustrated with Claude Sonnet 5

Paolino Di Felice
article en

Abstract

Students increasingly use large language models (LLMs) to translate natural-language requests into SQL, yet these models hallucinate: they return queries, numbers, explanations or assurances unsupported by the schema, data, or request, often in a form that executes without error. This paper proposes a teaching instrument for a first course on relational databases, designed to let students experience, recognize and prevent such failures; its contribution is conceptual and illustrative. This paper proposes a teaching instrument for a first course on relational databases that lets students experience, recognize, and prevent such failures. Its core is a taxonomy of fifteen hallucination categories that is coarse enough to serve as a classroom checklist, identified through an expert-driven process (the text-to-SQL literature and 27 years of teaching experience) and illustrated on a five-table PostgreSQL schema through constructed baseline outputs that the instructor can use to open a classroom discussion of each failure. Each category is paired with a two-layer mitigation: a context pack of standing rules and seven reference files, stored once in a Claude Project, and an agentic execute–observe–correct loop in which the assistant runs rule-prescribed checks against a live database before answering. Each countermeasure is assigned to the instructor, the loop, or the user. Nine categories have a counterpart in prior text-to-SQL taxonomies, two lack a dedicated one, and four concern the answer returned to the user rather than the query, thereby escaping static benchmark-based evaluation. The workflow is free for students. The effectiveness and generalizability of the mitigation have not yet been systematically validated; frequency and classroom effectiveness are left to future work.

Applied SciencesVol. 16(23)
Teaching and Learning Programming
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon