Large Language Models are Good Relational Learners

Fang Wu, Vijay Prakash Dwivedi, Jure Leskovec

Abstract

Relational databases (RDBs) underpin the majority of the world's structured data, yet they present significant challenges for Large Language Models (LLMs). Traditional serialization methods—flattening tables into text—often result in structural loss, extreme redundancy, and context window overflows. This paper discusses Rel-LLM, a novel framework that integrates Graph Neural Networks (GNNs) with LLMs to perform relational reasoning. By treating databases as heterogeneous graphs and using GNNs to generate "graph prompts," Rel-LLM preserves complex inter-table relationships and enables efficient reasoning. Experimental results on the RelBench benchmark demonstrate that Rel-LLM outperforms existing relational deep learning baselines and specialized tabular LLMs across diverse predictive tasks.

Introduction

Relational databases are the backbone of modern data infrastructure, powering approximately 73% of global data storage. These systems organize information into interconnected tables linked by primary and foreign keys. While LLMs have shown remarkable prowess in natural language tasks, their application to RDBs has been hindered by the "serialization bottleneck." Converting multi-table structures into a linear text format obscures the underlying graph topology and frequently exceeds the token limits of transformer architectures.

To address these challenges, we introduce Rel-LLM. This framework moves away from pure text serialization, instead employing a hybrid approach that leverages the structural inductive biases of Graph Neural Networks (GNNs) to inform the semantic reasoning of LLMs.

The Rel-LLM Framework

Rel-LLM conceptualizes a relational database as a heterogeneous graph where rows are nodes and relationships (keys) are edges. The architecture consists of several key components designed to bridge the gap between structured data and latent linguistic representations.

Graph Prompt Tuning

At the core of Rel-LLM is a heterogeneous GNN encoder (based on GraphSAGE). This encoder processes a local subgraph surrounding a target entity, capturing the multi-hop relationships and attributes of neighboring nodes. The resulting embedding is then projected into the LLM’s latent space as a "soft prompt." This allows the LLM to receive a compressed, structurally-aware representation of the database as a prefix to its standard text input.

Temporal-aware Subgraph Sampling

Relational data is often time-sensitive. To prevent data leakage—where information from the "future" informs a prediction about the "past"—Rel-LLM implements temporal-aware sampling. The system ensures that only neighbors and attributes existing before a specific "seed time" are included in the subgraph used for prompt generation.

Masked Table Modeling (Pretraining)

Before task-specific fine-tuning, the model undergoes a self-supervised pretraining phase called Masked Table Modeling. In this phase, the model learns to reconstruct missing attributes of an entity by analyzing its relational neighbors. A critical finding during development was that entity-level masking (masking entire rows) is significantly more effective than cell-level masking. Entity-level masking forces the model to learn the relational structure of the schema, whereas cell-level masking allows the model to exploit intra-row correlations.

Experimental Evaluation

The framework was rigorously tested using RelBench, a comprehensive benchmark for relational deep learning. RelBench includes seven diverse datasets—ranging from e-commerce (rel-amazon) and retail (rel-hm) to clinical trials (rel-trial) and Formula 1 racing (rel-f1)—covering 30 distinct predictive tasks.

Performance Metrics

Rel-LLM demonstrated state-of-the-art performance across both classification and regression tasks:

  • Classification: The model achieved an average AUROC of 77.82, surpassing the strongest GNN-only baseline (75.83).
  • Regression: In tasks such as predicting Lifetime Value (LTV) or engagement metrics, Rel-LLM consistently yielded the lowest Mean Absolute Error (MAE).
  • Zero-Shot Capabilities: A pretrained version of the model, Rel-Zero, demonstrated the ability to perform relational reasoning without task-specific labels, often outperforming traditional machine learning models like LightGBM.

Discussion and Insights

One of the most compelling aspects of Rel-LLM is its ability to synthesize structural data with the LLM's internal knowledge. For instance, on the rel-f1 dataset, the model combined database-specific race statistics with its pre-existing knowledge of Formula 1 drivers and circuits to produce highly accurate predictions.

Furthermore, the use of graph prompts provides a level of stability and scalability that standard In-Context Learning (ICL) lacks. While ICL is often sensitive to example selection and ordering, Rel-LLM’s embeddings remain robust across different sampling configurations. By avoiding quadratic scaling issues associated with long-text self-attention, Rel-LLM offers a more viable path for reasoning over massive, interconnected datasets.

Limitations and Future Directions

Despite its successes, Rel-LLM faces challenges in precise numerical reasoning, particularly with floating-point arithmetic. Current implementations utilize an MLP head for regression to mitigate this. Future research may explore deeper integration of graph embeddings via cross-attention mechanisms rather than simple prefix prompting. Additionally, extending the framework to more complex structures like knowledge graphs or multi-modal biomedical networks remains a promising frontier.

Conclusion

Rel-LLM represents a significant step forward in relational deep learning. By treating GNNs as translators that convert complex database topologies into a language LLMs can understand, the framework unlocks the ability to reason over the world’s most prevalent data format without the traditional pitfalls of serialization.

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