← Latest papers
💬 NLP

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

The paper proposes PGMR, a modular framework that reduces hallucinations in SPARQL query generation by having large language models produce intermediate queries with natural language placeholders that are subsequently resolved by a robust, non-parametric memory retrieval module, thereby significantly improving query correctness and safety across various datasets and distribution shifts.

Original authors: Aditya Sharma, Christopher J. Pal, Amal Zouaq

Published 2026-01-29
📖 4 min read☕ Coffee break read

Original authors: Aditya Sharma, Christopher J. Pal, Amal Zouaq

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a very smart, well-read librarian (the Large Language Model or LLM) who is great at writing stories and solving logic puzzles. However, this librarian has a strange quirk: when asked to look up specific items in a massive, chaotic library catalog (the Knowledge Graph), they often make up the shelf numbers. They might confidently say, "The book is on shelf Q937," even though that shelf doesn't exist. In the world of data, these fake shelf numbers are called hallucinated URIs, and they cause the librarian to fail at finding the right answer.

This paper introduces a new system called PGMR (Post-Generation Memory Retrieval) to fix this problem. Here is how it works, broken down into simple steps:

1. The Problem: The Librarian's Guessing Game

Normally, when you ask the librarian, "Who is the mayor of Hamburg?" they try to write a specific search query (called a SPARQL query) to find the answer. To do this, they need to know the exact, secret codes for "Hamburg" and "Mayor" in the library's system. Since they can't look these up while they are thinking, they rely on their memory. If their memory is fuzzy, they guess a code like Q12345. If that code is wrong, the search fails, or they return nonsense.

2. The Solution: The "Placeholder" Strategy

Instead of asking the librarian to guess the secret codes immediately, PGMR changes the rules of the game.

  • Step 1: The Draft (The Librarian's Job)
    The librarian is asked to write the search query using descriptive placeholders instead of secret codes.

    • Instead of: wd:Q1055 (a secret code for Hamburg)
    • They write: [ENT] Hamburg [/ENT] (A major city in northern Germany)
    • Instead of: wdt:P190 (a secret code for "twin city")
    • They write: [REL] twinned administrative body [/REL] (Cities that are sister cities)

    The librarian is now free to focus on the logic of the question (the sentence structure) without worrying about the specific, tricky codes. They are essentially writing a "rough draft" of the query.

  • Step 2: The Lookup (The Retriever's Job)
    Once the librarian finishes the draft, a separate, very precise tool (the Retriever) takes over. This tool has a perfect, up-to-date index of the library. It reads the librarian's descriptive notes ("Hamburg, major city in northern Germany") and instantly finds the real secret code (Q1055) that matches that description.

    It swaps the description for the real code, turning the rough draft into a final, working query.

3. Why This is a Game-Changer

The paper claims this method is a huge improvement for three main reasons:

  • It Stops the "Fake Codes" (Hallucinations):
    In previous tests, the librarian made up fake codes about 75% of the time. With PGMR, the fake code rate dropped to almost 0%. Because the librarian never has to guess the code, they can't make it up. The Retriever only uses codes that actually exist in the library.

  • It Knows When to Say "I Don't Know":
    Sometimes, the library simply doesn't have the answer. In the old system, the librarian would just guess a fake code and give a wrong answer. With PGMR, the Retriever checks its index. If it can't find a matching code for the description, it stops and says, "I can't find this." The paper shows the system can be tuned to refuse to answer when it's unsure, which makes it much safer and more trustworthy.

  • It's Tough Against Clutter:
    The researchers tested what happens if you fill the library's index with millions of irrelevant books (noise) to confuse the Retriever. Even when the memory was made 9 times larger with distracting, useless information, the system barely slowed down and still found the right codes. It's like finding a needle in a haystack even if someone throws 9 more haystacks on top of it.

The Bottom Line

Think of PGMR as a team where one person is the Architect (the LLM) who designs the blueprint, and another person is the Supplier (the Retriever) who finds the exact, real materials needed to build it. By separating the design from the material sourcing, the system ensures that the final building is constructed with real, existing parts, not imaginary ones.

The paper concludes that this simple separation allows AI to answer complex questions about structured data much more accurately and safely, without the annoying habit of making things up.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →