arXiv:2610.33756cs.CROct 2026

Manuscript Offprint

arXiv:2610.33756

Enhancing LLM-Based Vulnerability Detection via Representation-Aware Logical Ensemble

Francesco Crescenzo Grasso, Pietro Liguori, Roberto Natella, Domenico Cotroneo

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Francesco Crescenzo Grasso 1,∗^{1,*}[0009-0004-1551-1628], Pietro Liguori 1^{1}[0000-0001-5579-1696], Roberto Natella 2^{2}[0000-0003-1084-4824], and Domenico Cotroneo 3^{3}[0000-0001-7103-592X]

*corresponding author

1^{1} DIETI, University of Naples Federico II, Naples, NA 80125, Italy {francescocrescenzo.grasso,pietro.liguori}@unina.it

2^{2} Computer Science, Gran Sasso Science Institute, L'Aquila, AQ 67100, Italy roberto.natella@gssi.it

3^{3} Computer Science, University of North Carolina at Charlotte, Charlotte, NC 28223, USA

d.cotroneo@charlotte.edu

Abstract. Automated vulnerability detection in C source code is a longstanding challenge, as traditional static analysis tools often trade precision for scalability and struggle with complex vulnerability patterns. Recently, large language models (LLMs) have shown promising results; yet, most approaches rely on a single code representation, implicitly assuming uniform suitability across vulnerability types. In this work, we systematically study LLM-based vulnerability detection under multiple code representations, including raw source code, Abstract Syntax Trees (AST), and Control Flow Graphs (CFG). Through extensive empirical analysis, we show that different representations exhibit complementary strengths, with specific views being more effective for particular classes of vulnerabilities. Building on these findings, we propose a Representation-Aware Logical Ensemble (RALE) that integrates LLMs trained on different code representations through explicit logical rules and majority voting. While single-representation models achieve up to 73% F1-score, our integrated approach reaches 78% F1-score, with commensurate gains in accuracy, precision, and recall, consistently outperforming individual models. These results highlight the importance of explicitly leveraging complementary code representations when combining LLMs for effective vulnerability detection.

Keywords: Software Security · Vulnerability Detection · Code Representation Learning · Ensemble Learning.

1 Introduction

The detection of software vulnerabilities represents a key challenge in computer security. Weaknesses such as memory corruption errors and improper resource

F.C. Grasso et al.

management continue to be among the most exploited classes of vulnerabilities [10], motivating the need for automated and reliable detection techniques that can scale to large and complex codebases. Vulnerability detection traditionally relies on static or dynamic analysis. However, static tools tend to produce a high number of false positives [1], while dynamic tools are limited by execution coverage and computational costs [15]. Furthermore, both methods do not natively operate at a function-level granularity [12].

In recent years, data-driven approaches based on deep learning [2,3,9,14,23] have emerged as a promising alternative to traditional static analysis, aiming to automatically learn vulnerability patterns directly from source code. More recently, advances in large language models (LLMs) have further improved performance in a wide range of code-related tasks, including vulnerability detection, by leveraging large-scale pretraining and contextual representations.

Most of the state-of-the-art approaches process source code primarily as plain text [3,9,14], relying on token-based representations that only implicitly encode program semantics. As a result, crucial structural properties, e.g., syntactic hierarchy and control-flow behavior, are either weakly captured or entirely overlooked. Many studies [2,23] attempt to address these limitations by modeling code as graphs, such as Code Property Graphs (CPGs) or Abstract Syntax Trees (ASTs), explicitly encoding structural and execution-related information. These methods typically focus on a single representation and do not fully exploit the complementary nature of different program views. Consequently, their detection capability remains constrained to the specific aspects emphasized by the chosen representation.

In this work, we explore vulnerability detection through the lens of code representation. Rather than assuming a single optimal view of code, we investigate how different program representations, i.e., raw source code, Abstract Syntax Trees (ASTs), and Control Flow Graphs (CFGs), capture complementary vulnerability-related signals. Using real-world datasets, we systematically train and evaluate LLM-based classifiers on each representation and analyze their behavior at both global and vulnerability-type levels. Building on this analysis, we propose a representation-aware logical ensemble that combines predictions across heterogeneous representations using explicit and interpretable logical rules. The design of the ensemble is guided by security-oriented considerations, favoring decision strategies that mitigate missed vulnerabilities while preserving robustness on non-vulnerable samples.

Our work proposes the following contributions:

– We present a comprehensive evaluation of LLM-based vulnerability detection across heterogeneous code representations, showing that raw code, ASTs, and CFGs capture complementary security-relevant information and exhibit distinct specializations across vulnerability types.

– We introduce a Representation-Aware Logical Ensemble (RALE) that outperforms single-representation models and standard voting schemes, achieving up to 78% accuracy and F1-score on a real-world dataset.

The remainder of the paper is structured as follows. Section 2 elaborates on background concepts related to the target problem. Section 3 describes the methodology, including the extraction and generation of representations. Section 4 presents the experimental setup and the subsequent evaluation and analysis. Section 5 highlights the lessons learned. Section 6 examines related work, while Section 7 discusses threats to validity. Finally, Section 8 concludes the paper.

References (19)