Skip to main content
QUICK REVIEW

[Paper Review] Increasing the LLM Accuracy for Question Answering: Ontologies to the Rescue!

Dean Allemang, Juan Sequeda|arXiv (Cornell University)|May 20, 2024
Natural Language Processing TechniquesComputer Science3 citations
TL;DR

This paper proposes an ontology-driven framework to boost LLM-based question answering accuracy by combining deterministic ontology-based query checking (OBQC) with LLM-powered query repair. By validating SPARQL queries against semantic constraints and iteratively repairing errors using LLMs, the approach increases overall accuracy to 72.55% with a 20% error rate, including 8% unknown responses, significantly improving reliability over direct Text-to-SQL or Text-to-SPARQL methods.

ABSTRACT

There is increasing evidence that question-answering (QA) systems with Large Language Models (LLMs), which employ a knowledge graph/semantic representation of an enterprise SQL database (i.e. Text-to-SPARQL), achieve higher accuracy compared to systems that answer questions directly on SQL databases (i.e. Text-to-SQL). Our previous benchmark research showed that by using a knowledge graph, the accuracy improved from 16% to 54%. The question remains: how can we further improve the accuracy and reduce the error rate? Building on the observations of our previous research where the inaccurate LLM-generated SPARQL queries followed incorrect paths, we present an approach that consists of 1) Ontology-based Query Check (OBQC): detects errors by leveraging the ontology of the knowledge graph to check if the LLM-generated SPARQL query matches the semantic of ontology and 2) LLM Repair: use the error explanations with an LLM to repair the SPARQL query. Using the chat with the data benchmark, our primary finding is that our approach increases the overall accuracy to 72% including an additional 8% of "I don't know" unknown results. Thus, the overall error rate is 20%. These results provide further evidence that investing knowledge graphs, namely the ontology, provides higher accuracy for LLM powered question answering systems.

Motivation & Objective

  • To address the low accuracy of LLM-powered question answering systems over enterprise databases.
  • To reduce error rates in LLM-generated SPARQL queries by leveraging semantic constraints from knowledge graph ontologies.
  • To improve reliability and trustworthiness of LLM-based data querying in real-world enterprise applications.
  • To investigate whether ontology-aware validation and LLM-based repair can significantly enhance accuracy beyond existing Text-to-SPARQL or Text-to-SQL approaches.
  • To provide a deterministic, explainable, and governed method for improving LLM-generated queries using semantic metadata.

Proposed method

  • Ontology-based Query Check (OBQC) validates SPARQL queries using rules derived from the knowledge graph’s ontology, checking domain, range, and output constraints.
  • OBQC performs syntactic and semantic validation on both the query body (WHERE clause) and head (SELECT clause), detecting errors such as incorrect property direction or invalid subject types.
  • When OBQC detects an error, it generates a precise explanation (e.g., 'property domain mismatch') based on ontology semantics.
  • The LLM Repair component takes the erroneous query and the explanation as input, prompting the LLM to rewrite the query to fix the detected issue.
  • The repair process iterates up to three times, with OBQC revalidating each repaired query; if no fix is found, the system returns 'I don’t know'.
  • The framework integrates into a larger agent-based system, using retrieval-augmented generation principles to enhance trust and governance.
Figure 1: Overview of our Ontology-based Query Checker and LLM Repair approach
Figure 1: Overview of our Ontology-based Query Checker and LLM Repair approach

Experimental results

Research questions

  • RQ1How can ontology semantics be used to detect and explain errors in LLM-generated SPARQL queries?
  • RQ2To what extent can LLMs successfully repair SPARQL queries when guided by semantic error explanations?
  • RQ3What is the impact of combining ontology-based validation with LLM repair on overall QA accuracy?
  • RQ4Which types of query errors are most common and most effectively corrected by this approach?
  • RQ5How does the error distribution across ontology rules (e.g., domain, range, output) reflect underlying LLM reasoning patterns?

Key findings

  • The proposed approach increased overall question-answering accuracy to 72.55% on the chat-with-the-data benchmark, with an additional 8% of results classified as 'I don’t know'.
  • The overall error rate was reduced to 20%, with low-complexity questions on low-complexity schemas achieving an error rate of only 10.46%.
  • Domain-related rules were the most frequently triggered (42.16% of repairs), followed by domain-range checks (22.78%), indicating that LLMs often misplace subjects in triples.
  • The OBQC detected errors in 70% of cases via body-level checks (mainly domain constraints), while 30% were caught via head-level checks (e.g., IRI output validation).
  • The majority of repairs (55.57% average improvement) were achieved on high-complexity questions and schemas, demonstrating strong scalability.
  • Surprisingly, range-only rules were invoked less than 1% of the time, suggesting that LLMs are less likely to misassign object types than subject types.
Figure 2: Average Overall Execution Accuracy (AOEA) of SPARQL and SQL for all the questions in the benchmark from [ 12 ] compared to OBQC and LLM Repair
Figure 2: Average Overall Execution Accuracy (AOEA) of SPARQL and SQL for all the questions in the benchmark from [ 12 ] compared to OBQC and LLM Repair

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.