Actions Speak Louder than Prompts: A Large-Scale Study of LLMs for Graph Inference

Ben Finkelshtein, Silviu Cucerzan, Sujay Kumar Jauhar, Ryen W White

TL;DR

This paper presents a massive, systematic study of how Large Language Models (LLMs) perform node classification on text-rich graphs. The researchers find that treating a graph as a programmatic object—using Graph-as-Code—significantly outperforms standard prompting, especially on complex, long-text datasets where traditional prompts hit token limits.

The Challenge of Text-Rich Graphs

Graph Machine Learning (GML) has traditionally been the domain of Graph Neural Networks (GNNs). However, many real-world graphs, such as social networks or e-commerce platforms, are "text-rich," meaning the nodes contain valuable natural language data. While LLMs are natural candidates for processing this text, the field has lacked a principled understanding of how they should interact with the underlying graph structure.

Most existing research focuses on simple prompting—essentially serializing the graph's structure into a text block. This approach is brittle. It struggles with "heterophilic" graphs (where connected nodes are fundamentally different, like a buyer and a seller) and often fails when the graph's neighborhood is too large to fit into the LLM's context window. The authors set out to find a more robust way for LLMs to reason over relational data.

Interaction Modes: From Prompts to Code

The authors conducted a controlled evaluation across several axes of variability, but the core of their contribution lies in comparing three distinct interaction modes:

Three LLM-graph interaction modes: Prompting, GraphTool, and Graph-as-Code
  1. Prompting ($\phi_{prompt}$): The standard baseline. The graph structure (neighbors, labels, and text) is serialized into a single, long text prompt.
  2. GraphTool ($\phi_{tool}$): A ReAct-style agentic approach. The LLM can call specific tools to explore the graph (e.g., get_neighbors(node_id) or get_text(node_id)) in an iterative "think-act-observe" loop.
  3. Graph-as-Code ($\phi_{code}$): The most novel and effective approach. The graph is represented as a typed table (e.g., a Pandas DataFrame). The LLM generates and executes Python code to query the data, allowing it to perform complex aggregations or multi-hop lookups efficiently.

These modes were tested across different model sizes and reasoning capabilities on a diverse battery of 14 datasets, spanning short-text homophilic (e.g., Cora, ArXiv), heterophilic (e.g., Cornell, Texas), and long-text homophilic graphs (e.g., Wiki-CS, Reddit).

Key Insights and Robustness

  • The "Token Wall" is Real: Standard prompting collapses on dense or long-text graphs because it tries to dump all neighborhood information into the context window at once. Graph-as-Code bypasses this by surgically retrieving only the necessary data points via code execution.
  • LLMs are Heterophily-Resistant: A common myth in GML is that LLM-based methods fail on heterophilic graphs. This study proves otherwise. Because LLMs understand the semantics of the text, they do not just rely on neighbor voting; they can exploit non-local features that traditional GNNs might miss.
  • Agency Matters: The more agency the model has—moving from fixed tools to arbitrary code generation—the better it performs. This suggests the bottleneck in graph reasoning isn't just the model's knowledge, but the interface through which it accesses the graph.
  • Code is More Robust than Text: In stress tests where researchers randomly deleted edges or truncated text, Graph-as-Code remained remarkably stable compared to prompting.
Heatmaps showing model accuracy under feature and edge deletion. Graph-as-Code (bottom) shows greater robustness than Prompting (top).

As shown in the ablation heatmaps, Graph-as-Code demonstrates an "adaptive reliance." It flexibly shifts its focus to labels if features are missing, or to structural properties if labels are sparse, maintaining higher accuracy across degradation levels.

Key Results and Efficiency

  • Overall Performance: Graph-as-Code achieved the strongest results across the board. On long-text datasets like Wiki-CS, it outperformed 2-hop prompting by a wide margin (82.20% vs. a failure to even process the prompt due to token limits).
  • Efficiency: While iterative methods involve more turns, they are significantly more token-efficient. For the Wiki-CS dataset, 2-hop prompting would require over 1.1 million tokens per query, while Graph-as-Code used only ~57,000.
  • Reasoning Boost: Enabling reasoning modes (like Chain-of-Thought) provided a consistent accuracy boost across all interaction strategies, confirming that node classification is as much a logical task as it is a pattern-matching one.

Limitations and Future Work

While highly effective, the authors acknowledge that iterative interaction (Graph-as-Code) can be slower than a single-turn prompt due to multiple sequential LLM calls. Furthermore, the high number of API calls required for agentic reasoning can be expensive at scale compared to traditional small-scale GNNs. Because this study focused on frozen, off-the-shelf LLMs, future work should explore how fine-tuning specifically for Graph-as-Code execution could further bridge the gap between LLMs and specialized GNNs.

Summary updated

BibTeX
@inproceedings{finkelshtein2026actions,
  author = {Ben Finkelshtein and Silviu Cucerzan and Sujay Kumar Jauhar and Ryen W White},
  title = {{Actions Speak Louder than Prompts: A Large-Scale Study of LLMs for Graph Inference}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=MgJUj9Sk3C},
}
Figure