Efficient Graph Understanding with LLMs via Structured Context Injection

Govind Waghmare, Sumedh B. G, Sonia Gupta, Srikanta BedathurarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) frequently struggle with symbolic and algorithmic reasoning in graph-based tasks. This paper presents a framework for Structured Context Injection, a model-agnostic method that enhances graph reasoning by mapping abstract data to narrative structures. By leveraging "real-world" entity mapping (e.g., Game of Thrones characters) and a multi-model context generation pipeline, the proposed method allows lightweight models to achieve state-of-the-art performance on complex graph problems without fine-tuning.

Introduction

While LLMs demonstrate remarkable capabilities in natural language processing, their performance degrades significantly when faced with abstract graph problems, such as determining connectivity or finding shortest paths. This "grounding gap" stems from the models' difficulty in reasoning over symbolic numeric identifiers (e.g., Node 0, Node 1). Current solutions, such as extensive fine-tuning or multi-step querying, are often computationally expensive or model-specific.

This research addresses these challenges by introducing a framework that aligns graph structures with grounded conceptual representations, enabling LLMs to "see" the graph through familiar narrative lenses.

Methodology: Structured Context Injection

The proposed framework consists of three primary components designed to be cost-efficient and model-agnostic:

  1. Task-Specific Context: Instead of generic prompts, the framework embeds specific constraints and graph-aware cues directly into the input. This context is defined once at the task level, minimizing per-query overhead.
  2. Narrative-Based Entity Mapping: The core innovation involves mapping numeric node IDs to characters from well-known narratives, such as Game of Thrones (GOT). This allows the model to utilize its pre-trained semantic knowledge of relationships (alliances, rivalries) to interpret graph properties like edge weights.
  3. Approximate Subgraph Matching: To maintain mathematical integrity, specialized algorithms map the original numeric graph to a character-based subgraph, ensuring that structural properties like connectivity are preserved within the narrative.

The framework employs a "committee" approach for context generation, as illustrated in the following diagram.

The Structured Context Injection pipeline utilizing a committee of models to generate unified task context.

In this pipeline, multiple models (GPT-4, LLaMa3, and Gemini) contribute to context generation. These outputs are consolidated by GPT-4 into a single, high-quality structured input for the final downstream graph task.

Experimental Setup

The framework was evaluated using the NLGraphs benchmark (easy split) across four fundamental tasks: Connectivity, Cycle Detection, Topological Sort, and Shortest Path. Testing was conducted on Meta-LLaMa-3-8B-Instruct and Gemini 1.5 Flash to demonstrate the framework's effectiveness on both lightweight open-source and fast proprietary models.

Key Results and Discussion

The "GOT Subgraph" method consistently outperformed all baselines, including standard instruction-based prompting and Chain-of-Thought (CoT) techniques.

Comparative performance of various prompting methods across graph reasoning tasks.

As shown in the performance table above, the GOT Subgraph method achieved significant accuracy gains:

  • Connectivity: Reached 80.68% on LLaMa 3 8B and 95.74% on Gemini 1.5 Flash, a 6–7% improvement over the best baselines.
  • Shortest Path: On Gemini 1.5 Flash, path prediction accuracy reached 90.00%, significantly higher than zero-shot or few-shot approaches.
  • Efficiency: The results demonstrate that structured prompting can bridge the performance gap between small and large models. A well-prompted 8B model can rival much larger models using generic prompts.

Conclusion

Structured Context Injection provides a scalable, efficient path for improving LLM graph reasoning. By transforming abstract math into social network problems, models can leverage internal semantic maps for more accurate navigation. Future work will explore automating narrative template selection and testing the framework on larger, denser graphs where narrative construction becomes more complex.

Summary updated

Abstract

Large Language Models (LLMs) have shown strong capabilities in solving problems across domains, including graph-related tasks traditionally addressed by symbolic or algorithmic methods. In this work, we present a framework for structured context injection, where task-specific information is systematically embedded in the input to guide LLMs in solving a wide range of graph problems. Our method does not require fine-tuning of LLMs, making it cost-efficient and lightweight. We observe that certain graph reasoning tasks remain challenging for LLMs unless they are mapped to conceptually grounded representations. However, achieving such mappings through fine-tuning or repeated multi-step querying can be expensive and inefficient. Our approach offers a practical alternative by injecting structured context directly into the input, enabling the LLM to implicitly align the task with grounded conceptual spaces. We evaluate the approach on multiple graph tasks using both lightweight and large models, highlighting the trade-offs between accuracy and computational cost. The results demonstrate consistent performance improvements, showing that structured input context can rival or surpass more complex approaches. Our findings underscore the value of structured context injection as an effective and scalable strategy for graph understanding with LLMs.
BibTeX
@misc{waghmare2025efficient,
  author = {Govind Waghmare and Sumedh B. G and Sonia Gupta and Srikanta Bedathur},
  title = {{Efficient Graph Understanding with LLMs via Structured Context Injection}},
  year = {2025},
  eprint = {2509.00740},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.00740},
}
Figure