Text-to-SQL Interface using Guardrails and Hallucination Detection

Large Language Models (LLMs) can translate plain-English questions into SQL, which makes institutional databases usable by people who cannot write queries. In a shared system such as a college ERP, however, the generated SQL must be treated as untrusted code: it may modify data, read rows that belong to another user, or quietly answer the wrong question. This paper reports the design, deployment, and security testing of SafeSQL, a natural-language query system over a 25-table, 174- column PostgreSQL ERP schema holding about 200,000 records. SafeSQL places the LLM behind four independent layers: model-level refusal, syntax-tree (AST) blocking with sqlglot, a read-only non-owner database role, and Row-Level Security (RLS). We show that the widely used RLS pattern based on current_setting() can be defeated by generated SQL that calls set_config() from a subquery, CTE, LATERAL join, or window function, and we replace it with a session map keyed on the PostgreSQL backend process, which adds about 2.14 ms per query. We also describe five cases in which our own test infrastructure reported success for the wrong reason, and the checks we added to catch them. The system is deployed as a web application and is covered by 248 automated tests.

Authors

Publication Details

Journal
International Journal for Research in Applied Science and Engineering Technology
Published
2026-11-04
DOI
https://doi.org/10.22214/ijraset.2026.85358
Primary Topic
Access Control and Trust
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Text-to-SQL Interface using Guardrails and Hallucination Detection

P. V. Khopkar, Aditya Khot, Sumit Shendage, Shrikant Rathod et al.
International Journal for Research in Applied Science and Engineering Technology
Access Control and Trust
article

Text-to-SQL Interface using Guardrails and Hallucination Detection

P. V. Khopkar, Aditya Khot, Sumit Shendage, Shrikant Rathod, Prathamesh Gulavani, Pradnesh Khasnis
article en

Abstract

Large Language Models (LLMs) can translate plain-English questions into SQL, which makes institutional databases usable by people who cannot write queries. In a shared system such as a college ERP, however, the generated SQL must be treated as untrusted code: it may modify data, read rows that belong to another user, or quietly answer the wrong question. This paper reports the design, deployment, and security testing of SafeSQL, a natural-language query system over a 25-table, 174- column PostgreSQL ERP schema holding about 200,000 records. SafeSQL places the LLM behind four independent layers: model-level refusal, syntax-tree (AST) blocking with sqlglot, a read-only non-owner database role, and Row-Level Security (RLS). We show that the widely used RLS pattern based on current_setting() can be defeated by generated SQL that calls set_config() from a subquery, CTE, LATERAL join, or window function, and we replace it with a session map keyed on the PostgreSQL backend process, which adds about 2.14 ms per query. We also describe five cases in which our own test infrastructure reported success for the wrong reason, and the checks we added to catch them. The system is deployed as a web application and is covered by 248 automated tests.

International Journal for Research in Applied Science and Engineering TechnologyVol. 14(11)
Openalex Percentile: Top 8%
Access Control and Trust
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