Abstract
Unified Structured Knowledge Reasoning (USKR) aims to answer natural language questions by using structured sources such as tables, databases, and knowledge graphs in a unified way. Existing USKR methods rely on task-specific strategies or bespoke representations, which hinder their ability to dismantle barriers between different SKR tasks, thereby constraining their overall performance in cross-task scenarios. In this paper, we introduce PANDORA, a novel USKR framework that addresses the limitations of existing methods by leveraging two key innovations. First, we propose a code-based unified knowledge representation using Python's Pandas API, which aligns seamlessly with the pre-training of LLMs. This representation facilitates a cohesive approach to handling different structured knowledge sources. Building on this foundation, we employ knowledge transfer to bolster the unified reasoning process of LLMs by automatically building cross-task memory. By adaptively correcting reasoning using feedback from code execution, PANDORA showcases impressive unified reasoning capabilities. Extensive experiments on six widely used benchmarks across three SKR tasks demonstrate that PANDORA outperforms existing unified reasoning frameworks and competes effectively with task-specific methods.
Introduction
Structured Knowledge Reasoning (SKR) is a fundamental capability for AI systems, enabling them to answer questions based on diverse data formats like relational databases, spreadsheets, and knowledge graphs. Traditionally, these tasks have been treated as distinct domains: Text-to-SQL for databases, TableQA for spreadsheets, and KGQA for knowledge graphs.
This fragmentation creates a significant barrier: reasoning logic learned in one domain (e.g., filtering a database) is rarely transferable to another (e.g., traversing a knowledge graph) because the underlying query languages (SQL vs. SPARQL) and data structures are fundamentally different. Existing "unified" frameworks often struggle because they rely on custom representations that do not align with the pre-training data of Large Language Models (LLMs). PANDORA addresses this by standardizing all structured knowledge into a single, LLM-friendly format: Python Pandas code.
The PANDORA Framework
PANDORA introduces a three-pronged approach to unify structured reasoning:
- The BOX Representation: All structured data is converted into a unified "BOX" format based on the Python Pandas API. Tables are treated as DataFrames; databases are collections of DataFrames linked by foreign keys; and Knowledge Graphs are transformed into DataFrames by extracting relevant subgraphs.
- Code-driven Reasoning: Instead of generating direct answers or domain-specific queries, the LLM generates executable Pandas code. This leverages the extensive code-based pre-training of modern LLMs, allowing them to use compositional programming logic to solve complex reasoning problems.
- Execution-Guided Correction: PANDORA employs a "trial-and-error" mechanism. If the generated code fails to execute or returns an empty result, the error feedback is provided back to the LLM for self-correction.
Unifying Knowledge with Pandas
The core innovation of PANDORA is the realization that the Pandas API is expressive enough to serve as a "universal translator" for structured logic. As shown in Figure 1, complex operations that would require distinct syntax in SQL or SPARQL can be represented consistently in Python. This standardization removes the representational gap, allowing the model to build a "cross-task memory." A reasoning pattern learned from a database task can be directly applied to a knowledge graph query because the underlying language—Pandas—remains the same.
Experimental Evaluation
We evaluated PANDORA across six benchmarks covering three SKR tasks:
- Relational Databases: Spider and Spider-SYN.
- Tables: WikiTQ (WTQ) and WikiSQL.
- Knowledge Graphs: GrailQA and WebQSP.
Key Results
PANDORA consistently outperformed existing unified frameworks and remained competitive with state-of-the-art, task-specific models:
- Superior Accuracy: On the Spider (DB) benchmark, it achieved an execution accuracy of 81.7%. On WikiTQ (Table), it reached 68.9%, outperforming the next best unified model by over 7%.
- Efficiency: The Python-based execution achieved a 2.3x speedup compared to executing original query languages like SQL or SPARQL in the test environment.
- Ablation Study: Removing the "Code Unification" component caused the average score to drop from 80.3% to 62.9%, confirming that the code-based approach is the primary driver of success.
Discussion and Future Work
PANDORA demonstrates that leveraging the "coding brain" of LLMs is a highly effective strategy for unified reasoning. By treating structured data as DataFrames, we allow models to transfer logic across domains seamlessly. However, challenges remain regarding the computational cost of iterative execution guidance and the scalability of BOX conversion for extremely dense knowledge graphs. Future research will explore extending this framework to semi-structured text and optimizing memory retrieval to further enhance cross-task synergy.
Summary updated