InteracSPARQL : An Interactive System for SPARQL Query Refinement Using Natural Language Explanations

Xiangru Jian, Zhengyuan Dong, M. Tamer Özsu

TL;DR

InteracSPARQL is an interactive query generation and refinement system that makes querying semantic web data accessible to non-experts by using natural language explanations (NLEs). By pairing deterministic, rule-based parsing of SPARQL queries with the linguistic fluency of Large Language Models (LLMs), it creates a transparent feedback loop where both humans and LLMs can easily spot and fix query errors in real time. This interactive approach dramatically improves query accuracy on standard knowledge graph benchmarks while serving as an effective learning aid.

What Problem Does This Paper Address?

Querying the Semantic Web using SPARQL is notoriously difficult for non-experts. Unlike relational databases that use SQL with relatively straightforward schemas, SPARQL operates over graph-structured RDF (Resource Description Framework) data. It relies heavily on opaque Internationalized Resource Identifiers (IRIs)—such as wdt:P31 or wd:Q5398426—instead of human-readable text.

Existing Natural Language to SPARQL (NL2SPARQL) systems try to translate user questions into queries in a single shot. However, they suffer from low accuracy (often hovering around 20–40% F1 scores) because they struggle to map entities correctly or handle complex query logic without user guidance. Crucially, these systems lack transparency: when a query fails or returns empty results, users are left with an opaque wall of code and no way to understand what went wrong or how to fix it.

Methods

The authors introduce INTERACSPARQL, a system that breaks down query generation and refinement into a two-stage explanation framework and an interactive refinement loop.

  1. Two-Stage Natural Language Explanation (NLE) Framework:
  2. Stage 1 (Rule-based AST Analysis): The system parses the raw SPARQL query into an Abstract Syntax Tree (AST). It uses deterministic rules to break down complex components like Basic Graph Patterns (BGPs) and FILTER clauses into structured sentences. Opaque IRIs are replaced with human-readable labels via on-demand knowledge graph lookups. This ensures absolute factual accuracy and eliminates LLM hallucinations.
  3. Stage 2 (LLM Linguistic Refinement): An LLM takes this structured, factually accurate backbone and polishes it into a fluent, well-formatted JSON explanation detailing the overall intent, variables, and distinct query modules.
  4. Interactive Refinement Loop: Users (or an LLM simulating a user via "self-refinement") review the fluent explanation alongside the query's execution results. If errors are flagged (e.g., an incorrect entity ID), the system invokes a dynamic, tool-assisted entity and property search to retrieve the correct IRIs and incrementally update the query without breaking the already validated logic.
The detailed pipeline of the InteracSPARQL system, showing how raw SPARQL is parsed, explained, and iteratively refined.

Datasets

The system was evaluated using standard, human-annotated question-answering benchmarks over popular linked datasets:

  • QALD-9-Wikidata & QALD-9-DBpedia: Standard benchmarks covering a diverse array of SPARQL queries over the Wikidata and DBpedia knowledge graphs.
  • QALD-10: A more recent, highly challenging benchmark featuring increased query complexity and larger dataset sizes over Wikidata.

Key Insights and Ideas

  • Why Single-Shot LLMs Fail: A fine-grained error analysis revealed that LLMs do not fail at SPARQL due to a lack of syntactic or logical competence. Instead, they fail because they cannot reliably guess or map the exact, opaque entity and property IRIs in a single pass.
  • The Power of Hybrid Architectures: Relying solely on an LLM to explain code often introduces hallucinations. Using a rule-based AST parser as a "semantic backbone" guarantees factual grounding, allowing the LLM to focus entirely on what it does best: linguistic polishing and formatting.
  • Explanations as Debugging Scaffolding: Providing structured, modular NLEs acts as a critical anchor for feedback. It transforms a blind guessing game into a targeted debugging process, allowing the system to pinpoint exactly which clause or entity requires modification.
  • Diminishing Returns in Self-Refinement: While increasing the maximum refinement iterations ($N$) from 1 to 5 yields massive accuracy boosts, doubling it further to 10 iterations provides only marginal gains, demonstrating that most queries successfully converge within five rounds.

Key Results

  • Significant Accuracy Boosts: On the difficult QALD-10 benchmark, raw single-pass generation yields a dismal F1 score of 0.136 for GPT-4o. With INTERACSPARQL’s automated self-refinement loop, the F1 score jumps significantly to 0.393 for GPT-4o and 0.383 for Claude-3.5-Sonnet.
  • High Upper-Bound Potential: In an experiment where the system was provided with ground-truth NLEs to guide generation, it achieved near-perfect accuracy (F1 scores up to 0.959–0.974 across models), proving that high-quality explanations are incredibly powerful drivers for correct query formulation.
  • Strong Human Preference: A user study involving 20 graduate-level participants evaluated the explanations across four dimensions: aesthetics, clarity, completeness, and usefulness. The hybrid design consistently outperformed all ablated baselines, with participants noting that the structured format significantly reduced cognitive load.
Human evaluation results comparing the proposed design (OD) against ablated baselines across different models and datasets.

Limitations and Future Work

While INTERACSPARQL excels at standard graph patterns and filters, extremely advanced SPARQL features—such as deeply nested subqueries and highly intricate property paths—still present challenges for the explanation framework. Additionally, the entity and property linking tools are currently tailored for massive, open knowledge graphs like Wikidata and DBpedia; adapting the system to highly specialized or proprietary enterprise knowledge bases will require further engineering.

Moving forward, the authors plan to expand the system's feature coverage and explore deeper user-LLM collaboration models to make the interactive environment even more robust.

Summary updated

BibTeX
@inproceedings{jian2026interacsparql,
  author = {Xiangru Jian and Zhengyuan Dong and M. Tamer Özsu},
  title = {{InteracSPARQL : An Interactive System for SPARQL Query Refinement Using Natural Language Explanations}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.findings-acl.1480},
}
Figure