Reducing Hallucinations in Language Model-based SPARQL Query Generation Using Post-Generation Memory Retrieval

Aditya Sharma, Christopher Pal, Amal Zouaq


Abstract
The ability to generate SPARQL queries from natural language questions is crucial for ensuring efficient and accurate retrieval of structured data from knowledge graphs (KG). While large language models (LLMs) have been widely adopted for SPARQL query generation, they are often susceptible to hallucinations and out-of-distribution errors when generating KG elements, such as Uniform Resource Identifiers (URIs), based on opaque internal parametric knowledge. We propose PGMR (Post-Generation Memory Retrieval), a modular framework where the LLM produces an intermediate query using natural language placeholders for URIs, and a non-parametric memory module is subsequently employed to retrieve and resolve the correct KG URIs. PGMR significantly enhances query correctness (SQM) across various LLMs, datasets, and distribution shifts, while achieving the near-complete suppression of URI hallucinations. Critically, we demonstrate PGMR’s superior safety and robustness: a retrieval confidence threshold enables PGMR to effectively refuse to answer queries that lack support, and the retriever proves highly resilient to memory noise, maintaining strong performance even when the non-parametric memory size is scaled up to 9 times with irrelevant, distracting entities.
Anthology ID:
2026.findings-eacl.243
Volume:
Findings of the Association for Computational Linguistics: EACL 2026
Month:
March
Year:
2026
Address:
Rabat, Morocco
Editors:
Vera Demberg, Kentaro Inui, Lluís Marquez
Venue:
Findings
SIG:
Publisher:
Association for Computational Linguistics
Note:
Pages:
4657–4668
Language:
URL:
https://preview.aclanthology.org/ingest-eacl/2026.findings-eacl.243/
DOI:
Bibkey:
Cite (ACL):
Aditya Sharma, Christopher Pal, and Amal Zouaq. 2026. Reducing Hallucinations in Language Model-based SPARQL Query Generation Using Post-Generation Memory Retrieval. In Findings of the Association for Computational Linguistics: EACL 2026, pages 4657–4668, Rabat, Morocco. Association for Computational Linguistics.
Cite (Informal):
Reducing Hallucinations in Language Model-based SPARQL Query Generation Using Post-Generation Memory Retrieval (Sharma et al., Findings 2026)
Copy Citation:
PDF:
https://preview.aclanthology.org/ingest-eacl/2026.findings-eacl.243.pdf
Checklist:
 2026.findings-eacl.243.checklist.pdf