Abstract
Knowledge Base Question Answering (KBQA) requires translating natural language into complex logical forms like SPARQL. Current Large Language Model (LLM) approaches either suffer from hallucinations in end-to-end generation or error propagation in step-by-step reasoning. We present QueryAgent, a framework that models KBQA as a multi-turn interaction with an environment. Central to QueryAgent is ERASER, a module that utilizes environmental feedback—from database execution, code interpretation, and reasoning memory—to perform real-time self-correction. QueryAgent achieves state-of-the-art few-shot performance while significantly reducing computational costs compared to existing methods.
Introduction
Large Language Models (LLMs) have demonstrated remarkable capabilities in reasoning, yet Knowledge Base Question Answering (KBQA) remains a significant challenge. KBQA tasks require the model to navigate vast databases with complex schemas to produce precise logical queries. Existing methodologies typically fall into two categories: In-Context Learning (ICL) and Agent-based reasoning.
ICL-based methods often treat the LLM as a black box, generating entire queries in a single pass. This approach is highly susceptible to hallucinations, where the model references non-existent relations. Conversely, Agent-based methods decompose the task into sequential steps. While more interpretable, they suffer from "error propagation," where a minor mistake in an early step leads to a complete failure of the reasoning chain.
QueryAgent addresses these issues by integrating environmental feedback directly into the reasoning process, allowing for "purposeful" self-correction rather than blind re-generation.
Methodology: The QueryAgent Framework
QueryAgent treats KBQA as a multi-turn dialogue between an LLM agent and its execution environment. The process involves two key components: incremental query construction and the ERASER self-correction module.
Incremental Construction with PyQL
Instead of generating a full SPARQL query, QueryAgent uses PyQL, a Pythonic query language. This allows the model to build the query step-by-step, making the reasoning process more manageable and allowing for intermediate verification.
ERASER: Environmental Feedback-based Self-Correction
The core innovation is the ERASER (EnviRonmental feedbAck-based SElf-coRrection) module. At each reasoning step, ERASER monitors signals from three sources:
- Knowledge Base (KB) Feedback: Checks if a sub-query returns results. Empty results often indicate a hallucinated relation.
- Python Interpreter: Detects syntax errors or invalid function parameters in the generated PyQL.
- Reasoning Memory: Ensures consistency by checking if the model references undefined variables or entities.
When an error is detected, ERASER provides the LLM with specific guidelines derived from the environment (e.g., a list of valid relations for a specific entity). This feedback enables the model to immediately revise its path.
Experimental Evaluation
QueryAgent was evaluated on several prominent KBQA benchmarks, including GrailQA, GraphQ, WebQSP, and MetaQA-3Hop. It was also tested on WikiSQL to assess its transferability to Text-to-SQL tasks.
Key Results
- Superior Accuracy: In a few-shot setting, QueryAgent outperformed previous methods by significant margins. On GrailQA, it achieved a 5.7 F1 point improvement over methods using 100x more examples. On GraphQ, the improvement was 15.0 F1 points.
- High Efficiency: Compared to ICL methods like KB-BINDER, which may require thousands of candidate queries and subsequent filtering, QueryAgent typically reaches the correct answer in approximately five queries.
- Cost Reduction: The framework reduced API invocation costs and runtime by 50% compared to standard agent-based methods by pruning erroneous reasoning paths early.
- Generalizability: Plugging the ERASER module into other baselines like AgentBench resulted in performance gains of up to 10.5 points, demonstrating its utility as a universal booster for reasoning agents.
Discussion and Conclusion
The success of QueryAgent highlights the importance of the "Environment as a Teacher." The execution environment provides a ground-truth signal that is far more reliable than the internal probabilistic weights of an LLM. By leveraging this feedback, QueryAgent transforms "blind" self-correction into a targeted, efficient process.
While highly effective at catching structural and execution errors, QueryAgent still faces challenges with high-level semantic errors where a query might be executable but does not align with the user's intent. Future work will focus on refining prompt strategies and expanding the library of correction guidelines to handle more nuanced reasoning failures.
Summary updated