Manuscript Offprint

arXiv:2610.09605

GRAML: Graph-Grounded Reasoning and Multi-Task Learning for LLM-Based Software Vulnerability Detection

Ruohan Li, Miaoqing Tian, Haipeng Qu, Ruobing Jiang

Ruohan Li, Miaoqing Tian, Haipeng Qu, and Ruobing Jiang

Abstract—Large Language Models (LLMs) have been widely applied to software vulnerability detection. However, their performance is often limited by insufficient use of control-flow and dataflow information. In this paper, we propose GRAML, a framework that combines graph evidence, vulnerability description generation, and multi-task training. GRAML first performs static analysis on C/C++ programs to extract critical source lines and typed line relations as structural evidence. It then uses this evidence to guide GPT-5 through the Tree-of-Thought-guided Vulnerability Reasoning (ToT-VR) process and generate vulnerability descriptions. These descriptions are further combined with Detection, Localization, and Assessment samples to build a unified four-task training dataset. We evaluate GRAML on an in-distribution (ID) test set and six out-of-distribution (OOD) datasets. The results show that GRAML achieves average F1 scores ranging from 66.67% to 68.70%, outperforming state-of-the-art baselines by up to 30.92%. Ablation experiments further show that ToT-VR and graph-guided vulnerability descriptions improve detection performance compared with standard Chain-of-Thought (CoT) reasoning and raw Code Property Graph (CPG) serializations. These findings provide practical guidance for building more reliable and secure software engineering systems with large language models.

Index Terms—Software vulnerability detection, large language models, multi-task fine-tuning

I. INTRODUCTION

With the rapid advancement of software engineering, LLMs have shown considerable promise in automating software vulnerability detection [1]. By learning from large volumes of source code and historical vulnerability samples, LLMs can capture general programming patterns and security-related semantics, enabling them to identify potential vulnerability patterns in complex codebases. These capabilities allow LLM-based approaches to reduce manual rule design and feature engineering, making them attractive for scalable vulnerability detection [2]. Recent studies further show that LLMs have been used in different vulnerability analysis settings, including software security surveys [3], retrieval-based vulnerability detection [4], and inter-procedural semantic analysis [5].

However, existing LLMs mainly understand source code from tokens and labels, but make limited use of control-flow and data-flow information [6], [7]. As a result, they may miss how a vulnerability moves through the code from source to sink, making it difficult to identify its root cause [8]. This weakness can lead to both false positives, where benign code is misclassified as vulnerable, and false negatives, where real vulnerabilities are missed [9]. Existing studies have therefore explored additional program contexts and structural signals beyond binary labels, including vulnerability interpretation for LLM-based detection [10], CPG-guided context construction [11], and the fusion of language models and GNNs for joint semantic and structural modeling [12]. Fine-grained property graph representations [13] and augmented Program Dependence Graph (PDG)-based representations [14] have also been used to preserve control-flow, data-flow, and semantic information in vulnerability detection. Nevertheless, how to extract and organize these structural relations into an effective context for downstream vulnerability reasoning remains an open problem.

To address this challenge, we propose GRAML, a framework that integrates graph-based program information into LLM-based vulnerability detection. GRAML consists of graph evidence extraction, vulnerability description generation, and multi-task fine-tuning. During training data construction, we use Joern [15] to build Code Property Graphs (CPGs) [16]. We align graph nodes with physical source lines and retain data dependence, control dependence, and control flow relations. Starting from known vulnerable lines obtained from patch information or CVE records, GRAML applies reliability-aware propagation to select critical lines and typed line relations. The resulting graph evidence is then used to support vulnerability description generation.

Based on the extracted evidence, we design ToT-VR to generate vulnerability descriptions with GPT-5 [17]. The reasoning process uses the source code and available CVE information together with the selected critical lines and graph relations. It first constructs multiple candidate analyses. These candidates are then pruned, refined, and checked against the available evidence. The final output describes the vulnerability cause, the affected code regions, and the potential security consequences.

We then construct a training dataset using BigVul [18], DiverseVul [19], and newly collected CVE samples reported between 2019 and 2026. The dataset contains four tasks, namely Detection, Description, Localization, and Assessment. Detection determines whether the input code is vulnerable. Description explains the vulnerability cause, Localization identifies the affected code lines, and Assessment estimates the vulnerability severity. The descriptions generated by ToT-VR

Ruohan Li and Miaoqing Tian are with Qingdao University of Technology, Qingdao, Shandong, China (e-mail: liruohan@stu.qut.edu.cn; tianmiaoqing@qut.edu.cn).

Haipeng Qu and Ruobing Jiang are with Ocean University of China, Qingdao, Shandong, China (e-mail: quhaipeng@ouc.edu.cn; jrb@ouc.edu.cn).

Corresponding author: Miaoqing Tian.

Figure

Fig. 1: The Overview of GRAML.

are used for the Description task. All four tasks are combined to train the models jointly.

Using this multi-task dataset, we fine-tune CodeLlama, Mistral, DeepSeek, and Qwen in the GRAML framework. After fine-tuning, each model requires only source code during inference and performs the Detection task without graph evidence, vulnerable-line annotations, or CVE descriptions. We evaluate the four models on the in-distribution (ID) test set and six out-of-distribution (OOD) datasets. The experimental results show that their average F1 scores range from 66.67% to 68.70%, outperforming state-of-the-art baselines by up to 30.92%. Although these models use 6.7B–7B parameter backbones, they achieve higher average F1 scores than the larger general-purpose LLMs included in our evaluation. To provide a fair comparison with VulLLM [10], we replace GPT-5 with GPT-4 in GRAML while keeping the remaining settings unchanged. Under this setting, all four GRAML models achieve higher average F1 scores than the two VulLLM models. We further compare ToT-VR with standard Chain-of-Thought (CoT) and examine how graph evidence and its representation affect detection performance. We also evaluate model robustness under code transformations that preserve program behavior.

The main contributions of this paper are summarized as follows:

• Reliability-aware graph context extraction. We construct a sparse line-level CPG representation with typed data-dependence, control-dependence, and control-flow relations. The method combines vulnerable-line reliability, degree-normalized propagation, relation diversity, and redundancy control to select compact evidence for vulnerability reasoning.

• Graph-guided vulnerability reasoning with ToT-VR. We design a five-stage ToT-VR process based on GPT-5. It constructs multiple reasoning branches, removes unsupported analyses, refines the remaining candidates, verifies them against the available evidence, and generates the final vulnerability description. This process converts the extracted graph evidence into natural-language descriptions that are used for model training.

• Expanded multi-task vulnerability dataset. We construct a vulnerability training dataset by combining BigVul [18], DiverseVul [19], and newly collected CVE samples reported between 2019 and 2026. We organize the data into four tasks, including Detection, Description, Localization, and Assessment. These tasks provide supervision from vulnerability labels, causes, affected locations, and severity information to improve vulnerability detection.

The remainder of this paper is structured as follows. We first present the proposed GRAML framework and its key components in Section II. We then describe the experimental setup and analyze the results in Section III. Related work is reviewed in Section IV, followed by a discussion of the implications of our findings and potential limitations in Section V. Finally, Section VI concludes the paper and highlights future research directions.

References (60)

  • Securefalcon: Are we there yet in automated software vulnerability detection with llms?
  • Large language models for code analysis: Do {LLMs} really do their job?
  • Llms in software security: A survey of vulnerability detection techniques and insights
  • Vul-rag: Enhancing llm-based vulnerability detection via knowledge-level rag
  • Enhancing vulnerability detection via inter-procedural semantic completion
  • Sv-trusteval-c: Evaluating structure and semantic reasoning in large language models for source code vulnerability analysis
  • Iris: Llm-assisted static analysis for detecting security vulnerabilities
  • Vulnerability detection with code language models: How far are we? (opens arXiv in a new tab)
  • Enhancing the robustness of llm-generated code: Empirical study and framework (opens arXiv in a new tab)
  • Generalization-enhanced code vulnerability detection via multi-task instruction fine-tuning (opens arXiv in a new tab)
  • {LLMxCPG}: {Context-Aware} vulnerability detection through code property {Graph-Guided} large language models
  • Vul-lmgnns: Fusing language models and online-distilled graph neural networks for code vulnerability detection
  • Graphfvd: Property graph-based fine-grained vulnerability detection
  • Code vulnerability detection based on augmented program dependency graph and optimized codebert
  • Joern - home
  • Modeling and discovering vulnerabilities with code property graphs
  • Gpt-5 system card
  • Ac/c++ code vulnerability dataset with code changes and cve summaries
  • Diversevul: A new vulnerable source code dataset for deep learning based vulnerability detection
  • Tree of thoughts: Deliberate problem solving with large language models
  • Qwen2.5-Coder Technical Report
  • Code Llama: Open Foundation Models for Code
  • Mistral 7B
  • Deepseek-coder: When the large language model meets programming—the rise of code intelligence (opens arXiv in a new tab)
  • Pytorch: An imperative style, high-performance deep learning library
  • Transformers: State-of-the-art natural language processing
  • Cvefixes: automated collection of vulnerabilities and their fixes from open-source software
  • Devign: Effective vulnerability identification by learning comprehensive program semantics via graph neural networks
  • Juliet 1. 1 c/c++ and java test suite
  • Deep learning based vulnerability detection: Are we there yet?
  • Uncovering the limits of machine learning for automatic vulnerability detection
  • Vuldeepecker: A deep learning-based system for vulnerability detection (opens arXiv in a new tab)
  • Sysevr: A framework for using deep learning to detect software vulnerabilities
  • Security vulnerability detection using deep learning natural language processing
  • Vulnerability detection via multiple-graph-based code representation
  • Vulnerability detection by learning from syntax-based execution paths of code
  • Towards causal deep learning for vulnerability detection
  • Dataflow analysis-inspired deep learning for efficient vulnerability detection
  • Snopy: Bridging sample denoising with causal graph learning for effective vulnerability detection
  • Coca: Improving and explaining graph neural network-based vulnerability detection systems
  • Codebert: A pre-trained model for programming and natural languages
  • Graphcodebert: Pre-training code representations with data flow (opens arXiv in a new tab)
  • Stagedvulbert: Multigranular vulnerability detection with a novel pre-trained code model
  • Clever: Multi-modal contrastive learning for vulnerability code representation
  • From large to mammoth: A comparative evaluation of large language models in vulnerability detection
  • Combining structured static code information and dynamic symbolic traces for software vulnerability prediction
  • Llmdfa: analyzing dataflow in code with large language models
  • Towards generalizable instruction vulnerability prediction via llm-enhanced code representation
  • Keep it simple: Self-adaptive code graph simplification for accurate vulnerability detection
  • Litevul: a lightweight vulnerability detection via directed ppmi-weighted token graphs
  • Chain-of-thought prompting elicits reasoning in large language models
  • Self-Consistency Improves Chain of Thought Reasoning in Language Models
  • Large language model guided tree-of-thought (opens arXiv in a new tab)
  • Logs in, patches out: Automated vulnerability repair via {Tree-of-Thought}{LLM} analysis
  • {APPATCH}: Automated adaptive prompting large language models for {Real-World} software vulnerability patching
  • Multitask-based evaluation of open-source llm on software vulnerability
  • Lora: Low-rank adaptation of large language models
  • Qlora: Efficient finetuning of quantized llms
  • Towards explainable vulnerability detection with large language models
  • Core: Resolving code quality issues using llms