Introduction
Large Language Models (LLMs) are increasingly deployed as front-ends for Knowledge Graphs (KGs). However, they consistently stumble on complex queries involving negation. LLM-MatLogic introduces the Executable Exchange Contract (EEC), a structured interface allowing LLMs to specify exactly where and what to exclude during KG queries. By enforcing negation through a strict P→N→C/D (Produce-Negate-Compose/Disjunction) schedule, the system prevents common reasoning errors like "scope drift" and "evidence loss," significantly improving accuracy on complex, exclusion-rich questions.
The Challenge of Negation in Knowledge Graphs
In natural language, a request like "Find actors in Movie A but not in a cameo role" is notoriously tricky for two primary reasons:
- Scope Sensitivity: The "not" applies only to the Movie A branch of reasoning, not the entire query.
- Evidence Dependence: To filter out a cameo, the system must see the type of role (the evidence) before collapsing the data into a simple list of names (the projection).
Current systems often treat negation as a post-hoc filter (removing names from a final list) or apply it too broadly. This leads to "scope drift"—where a local exclusion accidentally wipes out valid answers from other parts of the query—or the loss of critical supporting evidence needed to make the exclusion in the first place.
Methodology: The Executable Exchange Contract and MatLogic
The authors propose a framework consisting of two main components designed to separate what to exclude from how to execute it:
- Executable Exchange Contract (EEC): This acts as a "handshake" between the Specifier (an LLM) and the Executor (MatLogic). Instead of sending a vague natural language query, the LLM generates a structured request identifying specific "scopes" (subgoals) and "banned sets" (entities or conditions to exclude).
- MatLogic Executor: A matrix-based engine that follows a canonical P→N→C/D schedule to ensure negation is enforced at the mathematically correct boundary:
- P (Produce): Generate intermediate evidence (witnesses) for all subgoals using sparse-matrix propagation.
- N (Negate): Apply scope-local masks to block witnesses traversing forbidden entities before any data is merged or projected.
- C/D (Compose/Disjunction): Combine the filtered results through logical conjunction (AND) and disjunction (OR).
Key Insights
- The Canonical Enforcement Boundary: The paper mathematically proves that for negation to be accurate, it must be enforced after evidence is produced but before it is projected or merged across disjunctive branches. Moving the "N" step elsewhere fundamentally changes the logic of the query.
- Negation is a Binding Problem: Diagnostic tests revealed that when the executor is given the "correct" constraints (oracle negation), performance jumps dramatically. This suggests the primary bottleneck is not the execution engine, but the LLM's ability to correctly "bind" the negation to the right scope during the specification phase.
- Efficiency via Matrices: By compiling exclusions into structural masks applied during matrix multiplication, the system remains highly efficient, typically returning answers in milliseconds even for complex subgraphs.
Empirical Results
The researchers evaluated the system on Complex Query Answering (CQA) using FB15k-237 and NELL995 (focusing on 14 query patterns, including negation-heavy ones like 2in, 3in, pni), and Natural Language KGQA using Complex WebQuestions (CWQ) and WebQSP.
- Superior Accuracy: LLM-MatLogic achieved the best average performance across standard CQA patterns. On the challenging FB15k-237 dataset, it reached an MRR of 58.2 on composition-heavy queries, nearly doubling the performance of the best prompting-based baseline (35.2).
- Negation Mastery: On negation-aware patterns, the system showed massive gains, outperforming baselines like LARK and BetaE by significant margins (e.g., 11.4 vs. 7.5 MRR on FB15k-237 for the
2inpattern). - Cost-Efficiency: In end-to-end KGQA, LLM-MatLogic matched or exceeded the accuracy of state-of-the-art multi-round systems (like ToG or MFC) while requiring significantly fewer LLM calls (3.0 vs. 9.7+), making it both faster and cheaper to run.
Limitations and Future Directions
Despite its strong performance, the system faces a few inherent limitations. First, linguistic ambiguity remains a challenge; if a natural language query is truly ambiguous (e.g., "Find movies without X and Y"), the LLM might still bind the exclusion to the wrong scope, leading to over- or under-exclusion. Second, like all KG-based systems, results are limited by Knowledge Graph incompleteness—if a "cameo" isn't labeled as such in the graph, the system cannot filter it.
Future work will likely involve stronger LLM compilation strategies to better handle linguistic nuances and the integration of application-level controls for high-stakes environments where accurate negation is critical.
Summary updated