SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2410.13080 · ICML · 2025

Graph-constrained Reasoning: Faithful Reasoning on Knowledge Graphs with Large Language Models

Chen Gong, Shirui Pan, Linhao Luo, Yuan-Fang Li, Gholamreza Haffari, Zicheng Zhao

arXiv · PDF · Open in the Atlas

Code that ran

3 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 2 failures of our instrument; 1 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2410.13080.json · badge: /api/ran/2410.13080.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
rmanluo/graph-constrained-reasoning canonical (classifier label)
classifier basis: classifier_2025
2 ran · 1 no recorded run
RManLuo/graph-constrained-reasoning canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FunctionStatusWhere it lives
GraphConstrainedDecoding Ran
ran on a synthesized input · constructed an object; no result was computed
RManLuo/graph-constrained-reasoning/src/graph_constrained_decoding.py
code served (permissive licence) · get_code("5738da564dd54ca1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, GraphConstrainedDecoding: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Stand-in tokenizer class with __len__ method
class StandInTokenizer:
    def __init__(self, vocab_size=100):
        self.vocab_size = vocab_size
    
    def __len__(self):
        return self.vocab_size

# Stand-in trie class with get method
class StandInTrie:
    def __init__(self):
        self.data = {
            tuple(): [10, 11, 12],  # root node returns some tokens
            (5, 6): [13, 14],        # example path
        }
    
    def get(self, path):
        """Get allowed tokens for a given path"""
        key = tuple(path) if isinstance(path, list) else path
        return self.data.get(key, [])

tokenizer = StandInTokenizer(vocab_size=100)
trie = StandInTrie()
start_token_ids = 1
end_token_ids = 2
enable_constrained_by_default = False

ARGS = {
    "tokenizer": tokenizer,
    "trie": trie,
    "start_token_ids": start_token_ids,
    "end_token_ids": end_token_ids,
    "enable_constrained_by_default": enable_constrained_by_default,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type GraphConstrainedDecoding — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a GraphConstrainedDecoding output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_output_file Ran
ran; our contract draft was wrong, not the code
rmanluo/graph-constrained-reasoning/workflow/predict_paths_and_answers.py
code served (permissive licence) · get_code("d57e3db685df5d73")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import tempfile
import json

# Create a temporary directory for testing
temp_dir = tempfile.mkdtemp()
test_file_path = os.path.join(temp_dir, "test_output.jsonl")

# Create a test file with some pre-existing data
with open(test_file_path, 'w') as f:
    f.write(json.dumps({"id": "item_1"}) + "\n")
    f.write(json.dumps({"id": "item_2"}) + "\n")

ARGS = {
    "path": test_file_path,
    "force": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
prediction Ran
ran; our contract draft was wrong, not the code
rmanluo/graph-constrained-reasoning/workflow/predict_paths_and_answers.py
code served (permissive licence) · get_code("0bcfb6bdefa6b543")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Stand-in tokenizer class
class StandInTokenizer:
    def convert_tokens_to_ids(self, tokens):
        if isinstance(tokens, str):
            return 101  # arbitrary token id
        return [101, 102]  # arbitrary token ids for list

# Stand-in input builder class
class StandInInputBuilder:
    PATH_START_TOKEN = "[PATH_START]"
    PATH_END_TOKEN = "[PATH_END]"
    
    def process_input(self, data):
        input_query = "What is the capital of France?"
        ground_paths = [["France", "capital", "Paris"]]
        # Simple trie-like structure (dict)
        trie = {"Paris": {"weight": 0.9}, "Lyon": {"weight": 0.1}}
        return input_query, ground_paths, trie

# Stand-in model class
class StandInModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.tokenizer = StandInTokenizer()
        self.embedding = nn.Embedding(1000, 4)
    
    def prepare_model_prompt(self, input_query):
        # Return a tensor representation of the prompt
        return torch.randn(2, 4)
    
    def generate_sentence(self, input_tensor, trie, start_token_ids, end_token_ids, enable_constrained_by_default=False):
        # Return a generated prediction string
        return "Paris is the capital of France"

# Construct the arguments
data = {
    'question': 'What is the capital of France?',
    'answer': 'Paris',
    'id': 'q_001'
}

processed_list = ['q_000', 'q_002']  # q_001 is not in this list

input_builder = StandInInputBuilder()

model = StandInModel()

ARGS = {
    'data': data,
    'processed_list': processed_list,
    'input_builder': input_builder,
    'model': model
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
merge_rule_result Not yet run
unverified (harvested, no recorded run)
rmanluo/graph-constrained-reasoning/workflow/predict_paths_and_answers.py
code served (permissive licence) · get_code("a86604eeda8184b9")
How it ran

no invocation recorded.

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 4 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Large language models (LLMs) have demonstrated impressive reasoning abilities, but they still struggle with faithful reasoning due to knowledge gaps and hallucinations. To address these issues, knowledge graphs (KGs) have been utilized to enhance LLM reasoning through their structured knowledge. However, existing KGenhanced methods, either retrieval-based or agentbased, encounter difficulties in accurately retrieving knowledge and efficiently traversing KGs at scale. In this work, we introduce graphconstrained reasoning (GCR), a novel framework that bridges structured knowledge in KGs with unstructured reasoning in LLMs. To eliminate hallucinations, GCR ensures faithful KG-grounded reasoning by integrating KG structure into the LLM decoding process through KG-Trie, a trie-based index that encodes KG reasoning paths. KG-Trie constrains the decoding process, allowing LLMs to directly reason on graphs and generate faithful reasoning paths grounded in KGs. Additionally, GCR leverages a lightweight KG-specialized LLM for graph-constrained reasoning alongside a powerful general LLM for inductive reasoning over multiple reasoning paths, resulting in accurate reasoning with zero reasoning hallucination. Extensive experiments on several KGQA benchmarks demonstrate that GCR achieves state-ofthe-art performance and exhibits strong zero-shot generalizability to unseen KGs without additional training 1 .

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2410.13080")
get_code_for_paper("2410.13080")
have("2410.13080")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2410.13080.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2410.13080.svg)](https://syntology.ai/paper/2410.13080)

Connect an agent — have() is free.