SECRLGOct 31, 2025

On Selecting Few-Shot Examples for LLM-based Code Vulnerability Detection

arXiv:2510.27675v11 citationsh-index: 6Has Code
Originality Incremental advance
AI Analysis

This work addresses the challenge of enhancing LLM performance in code security for developers, though it is incremental as it builds on existing in-context learning methods.

The paper tackles the problem of selecting few-shot examples for LLM-based code vulnerability detection, finding that criteria based on LLM mistakes and similarity improve detection accuracy by up to 15% on certain datasets.

Large language models (LLMs) have demonstrated impressive capabilities for many coding tasks, including summarization, translation, completion, and code generation. However, detecting code vulnerabilities remains a challenging task for LLMs. An effective way to improve LLM performance is in-context learning (ICL) - providing few-shot examples similar to the query, along with correct answers, can improve an LLM's ability to generate correct solutions. However, choosing the few-shot examples appropriately is crucial to improving model performance. In this paper, we explore two criteria for choosing few-shot examples for ICL used in the code vulnerability detection task. The first criterion considers if the LLM (consistently) makes a mistake or not on a sample with the intuition that LLM performance on a sample is informative about its usefulness as a few-shot example. The other criterion considers similarity of the examples with the program under query and chooses few-shot examples based on the $k$-nearest neighbors to the given sample. We perform evaluations to determine the benefits of these criteria individually as well as under various combinations, using open-source models on multiple datasets.

Foundations

The foundational work for this paper's niche, ranked by how specifically the neighbourhood builds on it — not by global fame.

Your Notes