Large Language Models are Good Relational Learners

Fang Wu, Vijay Prakash Dwivedi, Jure Leskovec

TL;DR

Rel-LLM bridges the gap between relational databases and large language models by using a Graph Neural Network (GNN) to encode complex data structures directly into an LLM's latent space. This approach avoids the pitfalls of flattening databases into text, resulting in superior efficiency, robustness, and predictive performance across relational learning tasks.

What Problem Does This Paper Address?

Relational databases form the backbone of global enterprise data, accounting for roughly 73% of the world's data. However, applying Large Language Models (LLMs) to reason over these interconnected tables remains a massive challenge.

Currently, engineers adapt LLMs to relational data by "serializing" it—essentially flattening tables and primary-foreign key connections into long strings of text. This text-based approach has three fatal flaws:

  1. Loss of Structure: It obscures the rich, multi-table graph topology inherent in relational databases.
  2. High Redundancy: Following nested data loops creates highly repetitive text prompts.
  3. Context Window Explosion: The resulting documents easily exceed standard LLM context lengths, leading to high memory overhead and reduced performance.

The authors introduce Rel-LLM to solve these issues by treating relational databases as heterogeneous graphs and feeding structured graph representations directly to the LLM.

Methods

Rel-LLM integrates GNNs, LLMs, and Retrieval-Augmented Generation (RAG) through a soft-prompting architecture:

Figure 1: Overview of the Rel-LLM framework. Input from a relational database is fed to an LLM through a graph encoder that captures local connectivity entities in different tables. The graph encoder, along with other trainable components, is pretrained with masked table modeling and fine-tuned for downstream tasks such as customer behavior prediction.
  • Temporal-aware Subgraph Sampling: To prevent data leakage and maintain causal consistency, the framework samples a local subgraph around a target entity, strictly ignoring any data points chronologically after a given "seed time."
  • Heterogeneous GNN Encoder: A variant of GraphSAGE processes the sampled subgraph to extract structural and temporal features into dense node embeddings.
  • Projection Layer & Graph Prompt Construction: Instead of translating data into text, an MLP projects these graph embeddings directly into the LLM's vector space. These "neural objects" are organized into a structured JSON format to preserve relational hierarchy without the token bloat of raw text.
  • Self-Supervised Pretraining: The model undergoes "Masked Table Modeling," where certain entity attributes are masked, and the LLM is tasked with reconstructing them from the corrupted subgraph. This aligns the graph representations with the LLM's text-compatible latent space.

Datasets

The model was evaluated on RELBENCH, a comprehensive benchmark containing 7 real-world relational datasets with a total of 30 predictive tasks. These datasets span various domains:

  • rel-amazon (E-commerce customer behavior)
  • rel-avito (Ad click-through rates)
  • rel-event (Event attendance)
  • rel-f1 (Formula 1 race results)
  • rel-hm (Fashion retail sales)
  • rel-stack (Stack Overflow user engagement)
  • rel-trial (Clinical trial outcomes)

Key Insights and Ideas

  • Embeddings as Prompts: By feeding dense GNN embeddings directly into the LLM's attention layers as soft prompts, Rel-LLM bypasses the token limits that plague traditional text serialization.
  • Extreme Robustness: Standard In-Context Learning (ICL) is notoriously unstable; slight changes in prompt order or example selection cause massive performance swings. Rel-LLM eliminates this variance because its structural graph prompts are inherently stable.
  • Zero-Shot Relational Learning: Thanks to its self-supervised pretraining phase, the model can generalize to relational tasks without any labeled training data (dubbed Rel-Zero), matching or beating traditional supervised baselines like LightGBM.

Key Results

Rel-LLM consistently outperformed standard GNN-based relational deep learning (RDL) and text-based LLM baselines across both classification and regression tasks.

  • Entity Classification: Rel-LLM achieved the highest average AUROC score of 77.82 on the test set, outperforming standard RDL (75.83) and text-based ICL + MLP (76.83).
  • Entity Regression: On numerical prediction tasks, Rel-LLM achieved the lowest Mean Absolute Error (MAE) of 12.306, significantly outperforming ICL + MLP (13.761), proving that graph-grounded reasoning helps LLMs overcome their inherent weaknesses in numerical reasoning.
Figure 2: Comparision of model prediction variation across different classification tasks.

As shown in the variance analysis above, Rel-LLM's performance remains tightly bounded and reliable compared to the highly volatile text-based ICL method.

Limitations and Future Work

While Rel-LLM marks a significant step forward, the authors note a few areas for improvement:

  • Cross-Attention Tuning: The current architecture freezes the LLM's attention layers. Modifying the cross-attention mechanism specifically to blend graph prompts and text embeddings could yield better alignment.
  • Scaling to Advanced LLMs: The experiments primarily utilized smaller models (Llama 3.2-1B and 3B). Integrating larger reasoning models, such as DeepSeek-R1, could drastically improve prompt accuracy and factual retrieval.
  • Domain Expansion: Future work will explore applying Rel-LLM to other complex structured data types, such as biomedical networks and financial transaction systems.

Summary updated

BibTeX
@inproceedings{wu2025large,
  author = {Fang Wu and Vijay Prakash Dwivedi and Jure Leskovec},
  title = {{Large Language Models are Good Relational Learners}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure