NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Benchmarking Large Language Models for Multi-Language Software Vulnerability Detection

Ting Zhang, Chengran Yang, Yindu Su, Martin Weyssow, Huu Hung Nguyen, Tan Bui, Hong Jin Kang, Yikun Li, Eng Lieh Ouh, Lwin Khin Shar, David LoarXiv 2025 · DOI

TL;DR

This paper presents a comprehensive benchmark of Large Language Models (LLMs) for detecting software vulnerabilities across Python, Java, and JavaScript. It reveals that while LLMs show promise, their effectiveness varies significantly by programming language and adaptation strategy, with fine-tuning being most effective on balanced datasets.

What Problem Does This Paper Address?

Software vulnerabilities are a major security concern, and automatically detecting them is crucial. While LLMs have shown potential in various software engineering tasks, their effectiveness in Software Vulnerability Detection (SVD) remains underexplored, especially across multiple programming languages. Existing research often focuses on C/C++ and uses limited evaluation strategies. This paper aims to bridge this knowledge gap by providing a thorough, multi-language evaluation of LLMs for SVD, comparing them against smaller models and traditional Static Application Security Testing (SAST) tools.

Methods

The authors employ a multi-faceted approach to evaluate LLMs for SVD:

  • Prompt Engineering: This involves using LLMs without updating their parameters. They explore three strategies:
  • Zero-shot: Providing only the task instruction and the code.
  • In-Context Learning (ICL): Including a few examples of code and their vulnerability labels in the prompt.
  • Retrieval-Augmented Generation (RAG): Retrieving similar code examples from a knowledge base to guide the LLM.
  • Fine-tuning LLMs: This involves updating the LLM's parameters using a training dataset. They use Parameter-Efficient Fine-Tuning (PEFT) with QLoRA, a technique that significantly reduces computational requirements. Two fine-tuning strategies are explored:
  • Instruction Tuning: Training the model to predict the next token in a sequence, aiming to generate vulnerability labels.
  • Sequence Classification Fine-tuning: Adding a classification head to the LLM to directly predict a binary vulnerable/non-vulnerable label.
  • Model Comparison: LLMs are compared against five smaller language models (SLMs) and two SAST tools (Semgrep and SonarQube).
  • Data Perspective Improvement: Investigating the impact of downsampling non-vulnerable functions to create more balanced datasets.
  • Model Perspective Improvement: Exploring ensemble learning by combining predictions from multiple models.

Datasets

The study utilizes a newly compiled dataset of vulnerable functions from projects written in Python, Java, and JavaScript. This dataset comprises:

  • 8,260 vulnerable functions in Python
  • 7,505 vulnerable functions in Java
  • 28,983 vulnerable functions in JavaScript

The data was collected from the National Vulnerability Database (NVD) and processed using Tree-sitter to extract functions from vulnerability-fixing commits (VFCs). A time-aware split was implemented for training, validation, and testing.

Key Insights and Ideas

  • Language Matters: LLM performance for SVD varies significantly across programming languages. JavaScript, with a more balanced dataset ratio, shows better results for fine-tuned models compared to Python and Java.
  • Fine-tuning vs. Prompting: Fine-tuning LLMs generally yields better results than prompt engineering, especially when sufficient and balanced training data is available. However, prompt engineering can be more effective in low-data scenarios or with highly imbalanced datasets.
  • Data Imbalance is Key: The imbalance between vulnerable and non-vulnerable functions significantly impacts LLM performance. Downsampling non-vulnerable functions to create balanced datasets improved performance for Python and Java, but had mixed results for JavaScript due to its already relatively balanced nature.
  • SAST Tools Lag Behind: Traditional SAST tools consistently underperform LLMs and SLMs across all programming languages, highlighting the potential of LLMs in this domain.
  • Model-Specific Strategies: Different LLMs respond differently to various adaptation strategies (zero-shot, ICL, RAG, fine-tuning), suggesting that tailored approaches are necessary for optimal performance.

Key Results

  • Overall LLM Performance: LLMs generally struggle with SVD, with the best F1 scores for Python and Java being around 0.20-0.23. JavaScript shows higher performance, with some models reaching F1 scores around 0.44.
  • Fine-tuning Effectiveness: Sequence classification fine-tuning with QLoRA significantly improved LLM performance on the JavaScript dataset, with F1 scores increasing by up to 757.4% compared to zero-shot prompting. However, fine-tuning showed detrimental effects on Python and Java, often leading to near-zero F1 scores.
  • Prompt Engineering Benefits: Prompt engineering (ICL and RAG) generally improved LLM effectiveness for Python and Java, but not for JavaScript.
  • SLM vs. LLM vs. SAST: SLMs outperformed LLMs in Java and JavaScript but underperformed in Python. SAST tools consistently performed worse than both LLMs and SLMs.
  • Data Downsampling: Training on downsampled, balanced datasets improved F1 scores for Python and Java, but the effect was inconsistent for JavaScript.
  • Ensemble Learning Ineffectiveness: Simple majority voting ensemble methods did not yield improvements over single-model performance in this study, possibly due to issues with time-aware data splits and model selection.

Limitations and Future Work

  • Dataset Scope: The study focuses on vulnerabilities recorded in the NVD. Future work could extend to vulnerabilities from diverse resources.
  • Data Imbalance Impact: The paper acknowledges that data imbalance is a significant factor and suggests future research to explore varying ratios of vulnerable to non-vulnerable functions.
  • Model-Specific Tailoring: The authors recommend conducting preliminary experiments to determine the most effective strategy for each LLM and task combination.
  • Ensemble Learning: The current ensemble approach was not effective. Future work could explore more sophisticated ensemble methods and LLM collaboration strategies.
  • Advanced Prompting: Investigating more advanced prompt engineering techniques is suggested for future improvements.

Summary updated

BibTeX
@misc{zhang2025benchmarking,
  author = {Ting Zhang and Chengran Yang and Yindu Su and Martin Weyssow and Huu Hung Nguyen and Tan Bui and Hong Jin Kang and Yikun Li and Eng Lieh Ouh and Lwin Khin Shar and David Lo},
  title = {{Benchmarking Large Language Models for Multi-Language Software Vulnerability Detection}},
  year = {2025},
  eprint = {2503.01449},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.01449},
}
Figure