GraphStateEval: A Step-by-Step Evaluation Framework for Graph Algorithm Execution in Large Language Models via Intermediate State Tracing

Kanav Kapoor, Jagat Sesh Challa, Yash Sinha, Murari Mandal, Dhruv KumarCTB @ ICML 2026

TL;DR

GraphStateEval is a new evaluation framework that moves beyond "final answer" testing to measure how accurately LLMs maintain internal memory states (like queues and stacks) during graph algorithm execution. The researchers discovered a significant "SEM–FAC gap," revealing that models often "reward hack"—producing correct final answers despite having completely broken internal logic.

What Problem Does This Paper Address?

If you ask an LLM to find the shortest path in a graph, it might give you the right answer. But did it actually execute Dijkstra’s algorithm, or did it just recognize a pattern in the graph structure and make an educated guess?

Current benchmarks suffer from two main issues:

  1. Final-Answer Bias: They only check the output. This allows for "algorithmic reward hacking," where a model bypasses the logic but stumbles onto the correct result.
  2. Teacher Forcing: Many step-by-step evaluations provide the model with the correct previous state before asking for the next one. This prevents "cascading failures," making the model seem much more competent at autonomous reasoning than it actually is.

The authors argue that to truly trust an LLM with complex reasoning, we need to see its "scratchpad"—the internal data structures it maintains at every single iteration of a loop.

Methods

The authors introduced GraphStateEval, a framework that requires models to output a structured JSON snapshot of their internal memory at every step of an algorithm.

Key components include:

  • Step-Exact-Match (SEM): A rigorous metric that awards a point only if every part of the model's internal state (e.g., the current queue, the visited set, and the neighbors being processed) matches the ground truth exactly.
  • Deterministic Ground Truth: To ensure there is only one "right" way to execute the algorithm, the authors implemented canonical tie-breaking rules (e.g., always visit the neighbor with the smallest ID first).
  • Dual Prompting Strategies: They compared Natural Language (NL) prompts (describing the algorithm in English) against Source Code prompts (asking the model to simulate a specific Python implementation).
  • Zero-Shot Execution: No examples are provided, and no corrections are made mid-way. The model must run the entire algorithm from start to finish autonomously.

Datasets

The researchers developed a fully parametric dataset generator. Instead of static graphs that might be in the training data, they generate graphs on the fly across five topologies:

  1. Path: A simple linear chain.
  2. Complete: Every node is connected to every other node.
  3. Tree: Irregular, hierarchical branching.
  4. Sparse Random: Low-density connections.
  5. Dense Random: High-density connections.

They scaled these graphs from $N=3$ to $N=12$ nodes and evaluated the Gemma 3 12B model on three classic algorithms: Breadth-First Search (BFS), Depth-First Search (DFS), and Dijkstra’s.

Key Insights and Ideas

  • The "Reward Hacking" Phenomenon: The most striking finding is the gap between SEM (step-level accuracy) and FAC (final-answer correctness). In BFS on complete graphs, the model maintained 100% final-answer accuracy even when its internal state tracking had collapsed to near 20%. The model "knows" what the traversal should look like but has lost track of the queue.
  • Topology as Complexity: Graph size ($N$) isn't the only thing that matters. Path graphs are easy because the memory load is constant. Sparse-random graphs are the "LLM killers"—their lack of regular patterns forces the model to rely entirely on its (often failing) internal state tracking.
  • Code vs. Natural Language: There is no "best" way to prompt. Python code prompts helped the model handle the "flooding" of the queue in complete graphs but actually hindered it in Dijkstra’s algorithm, where the complexity of simulating a Python heapq (priority queue) created "idiom overhead" that led to more errors.

Key Results

  • BFS is the "easiest": It maintains a single, predictable data structure. Gemma 3 12B performed well here up to $N=10$ on regular topologies.
  • DFS and Dijkstra are "fragile": Performance on these algorithms collapsed much earlier (often by $N=6$). DFS is particularly hard because it requires "backtracking"—recalling nodes from much earlier in the conversation history, which conflicts with the recency bias inherent in Transformer models.
  • The Scaling Wall: For most complex topologies, SEM scores dropped toward zero as the number of nodes approached 12, even when the model was still occasionally guessing the right final answer.

Limitations and Future Work

The authors acknowledge that this was an exploratory pilot study using a single-seed evaluation on one model (Gemma 3 12B). Because graph performance is highly sensitive to specific edge placements, future work needs to average results across multiple seeds and different model families (like "reasoning" models vs. standard autoregressive ones).

They also suggest expanding the framework to more complex algorithms like Bellman-Ford or Prim’s and investigating whether fine-tuning LLMs specifically on these intermediate state traces can improve their general algorithmic reasoning.

Summary updated

BibTeX
@inproceedings{kapoor2026graphstateeval,
  author = {Kanav Kapoor and Jagat Sesh Challa and Yash Sinha and Murari Mandal and Dhruv Kumar},
  title = {{GraphStateEval: A Step-by-Step Evaluation Framework for Graph Algorithm Execution in Large Language Models via Intermediate State Tracing}},
  booktitle = {CTB @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=1IJRLpRNkN},
}
Figure