Benchmarking LLMs and LLM-based Agents in Practical Vulnerability Detection for Code Repositories

Alperen Yildiz, Sin G. Teo, Yiling Lou, Yebo Feng, Chong Wang, Dinil Mon Divakaran · DOI

Introduction

Just-In-Time (JIT) vulnerability detection represents a critical frontier in software security. Unlike traditional static analysis, JIT detection aims to identify vulnerabilities at the moment they are introduced into a codebase. However, existing research has largely focused on "function-level" analysis, where Large Language Models (LLMs) are tasked with identifying bugs in isolated code snippets. This approach fails to capture the complexity of real-world vulnerabilities, which are often interprocedural—manifesting through intricate call chains across multiple files.

This paper introduces JITVUL, a novel benchmark designed to bridge the gap between academic evaluation and practical utility. By requiring models to distinguish between a vulnerable code commit and its corresponding patch, JITVUL tests a model's true reasoning capabilities rather than its ability to recognize superficial patterns.

The JITVUL Benchmark

JITVUL is specifically structured for pairwise evaluation. It comprises 879 Common Vulnerabilities and Exposures (CVEs) across 91 different Common Weakness Enumeration (CWE) types, totaling 1,758 samples. Each sample pair includes the "vulnerability-introducing" commit and the "vulnerability-fixing" commit.

Unlike previous benchmarks such as Devign or BigVul, JITVUL provides full repository context. To succeed, a model must correctly label both the vulnerable and the patched versions of the code. This "pairwise accuracy" (pAcc) serves as a more rigorous metric than standard F1 scores, as it prevents models from scoring well simply by being overly sensitive to any code change.

Methodology: From Plain LLMs to ReAct Agents

The researchers evaluated three distinct architectural approaches to vulnerability detection:

  1. Plain LLM: The model is provided only with the target function and asked for a security assessment.
  2. Dependency-Augmented (Dep-Aug) LLM: The model receives the target function along with the "Top-5" most similar callers and callees, retrieved via Jaccard similarity. This provides static context without iterative exploration.
  3. ReAct Agent: This approach utilizes a "Thought-Action-Observation" loop. The LLM is equipped with specialized tools to explore the repository dynamically, including get_callers, get_callees, and get_definition. This allows the agent to selectively retrieve context based on its evolving understanding of the code logic.

These methods were tested using various prompting strategies—Vanilla, Chain-of-Thought (CoT), and Few-Shot (FS)—across models including GPT-4o, GPT-4o-mini, and Llama-3.1-8B.

Key Insights and Results

The F1 Score Mirage and Pairwise Accuracy

One of the paper's most significant findings is the "F1 Score Mirage." Standard LLMs often achieve high F1 scores because they are "trigger-happy," frequently predicting "vulnerable" for almost any complex code. While this results in high recall, it fails in practice. In the JITVUL benchmark, standard LLMs achieved pairwise accuracy (pAcc) scores as low as 1-3%. In contrast, ReAct agents reached over 20% pAcc, demonstrating a significantly better ability to distinguish a fix from a bug.

The "Security Guard" Paradox

When analyzing patched code, LLMs frequently fall victim to the "Security Guard" paradox. Models often over-analyze new security checks—such as added if statements for input validation—and hallucinate that these very fixes are vulnerabilities. This suggests that without iterative reasoning, models struggle to understand the intent of code changes.

Agentic Superiority and Model Performance

ReAct agents consistently outperformed other methods, showing improvements of up to 16.6% in pAcc over standard LLM approaches. Interestingly, GPT-4o-mini occasionally outperformed the larger GPT-4o in agentic tasks, suggesting that smaller, optimized models can be highly effective when provided with the right tools. Conversely, the open-source Llama-3.1-8B struggled with the ReAct loop, often failing to maintain the required output format, which led to poor performance.

Retrieval vs. Agency

Simply providing more context (the Dep-Aug approach) often introduced "noise" that confused the models. The ReAct agents' success stems from their ability to selectively pull relevant context. By iteratively deciding which functions to inspect, the agents maintain a cleaner reasoning path compared to static retrieval methods.

Limitations and Future Directions

While ReAct agents show great promise, several hurdles remain for real-world deployment:

  • Cost and Latency: The iterative nature of agentic loops is significantly slower and more expensive than single-shot inference, posing challenges for integration into real-time CI/CD pipelines.
  • Reasoning Robustness: Even the best-performing agents showed inconsistent analysis patterns between the vulnerable and benign versions of the same code, indicating that deep program semantics are still not fully mastered.
  • Dataset Realism: While JITVUL is label-balanced (50/50), real-world repositories are "needles in a haystack" scenarios. Future work must evaluate these agents in environments where vulnerabilities are extremely rare.

Conclusion

The shift from function-level analysis to repository-level agentic exploration marks a major step forward in AI-driven security. By moving beyond simple pattern matching and toward iterative, tool-based reasoning, ReAct agents provide a more reliable path toward practical, automated vulnerability detection.

Summary updated

BibTeX
@inproceedings{yildiz2025benchmarking,
  author = {Alperen Yildiz and Sin G. Teo and Yiling Lou and Yebo Feng and Chong Wang and Dinil Mon Divakaran},
  title = {{Benchmarking LLMs and LLM-based Agents in Practical Vulnerability Detection for Code Repositories}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure