On the Difficulty of Selecting Few-Shot Examples for Effective LLM-based Vulnerability Detection

Fuente: arXiv
Guardado en:
Detalles Bibliográficos
Autores principales: Hannan, Md Abdul, Ni, Ronghao, Zhang, Chi, Jia, Limin, Mangal, Ravi, Pasareanu, Corina S.
Formato: Preprint
Publicado: 2025
Materias:
Acceso en línea:
Etiquetas: Agregar Etiqueta
Sin Etiquetas, Sea el primero en etiquetar este registro!
_version_ 1866911420169322496
author Hannan, Md Abdul
Ni, Ronghao
Zhang, Chi
Jia, Limin
Mangal, Ravi
Pasareanu, Corina S.
author_facet Hannan, Md Abdul
Ni, Ronghao
Zhang, Chi
Jia, Limin
Mangal, Ravi
Pasareanu, Corina S.
contents Large language models (LLMs) have demonstrated impressive capabilities across a wide range of coding tasks, including summarization, translation, completion, and code generation. Despite these advances, detecting code vulnerabilities remains a challenging problem for LLMs. In-context learning (ICL) has emerged as an effective mechanism for improving model performance by providing a small number of labeled examples within the prompt. Prior work has shown, however, that the effectiveness of ICL depends critically on how these few-shot examples are selected. In this paper, we study two intuitive criteria for selecting few-shot examples for ICL in the context of code vulnerability detection. The first criterion leverages model behavior by prioritizing samples on which the LLM consistently makes mistakes, motivated by the intuition that such samples can expose and correct systematic model weaknesses. The second criterion selects examples based on semantic similarity to the query program, using k-nearest-neighbor retrieval to identify relevant contexts. We conduct extensive evaluations using open-source LLMs and datasets spanning multiple programming languages. Our results show that for Python and JavaScript, careful selection of few-shot examples can lead to measurable performance improvements in vulnerability detection. In contrast, for C and C++ programs, few-shot example selection has limited impact, suggesting that more powerful but also more expensive approaches, such as re-training or fine-tuning, may be required to substantially improve model performance.
format Preprint
id arxiv_https___arxiv_org_abs_2510_27675
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle On the Difficulty of Selecting Few-Shot Examples for Effective LLM-based Vulnerability Detection
Hannan, Md Abdul
Ni, Ronghao
Zhang, Chi
Jia, Limin
Mangal, Ravi
Pasareanu, Corina S.
Software Engineering
Cryptography and Security
Machine Learning
Large language models (LLMs) have demonstrated impressive capabilities across a wide range of coding tasks, including summarization, translation, completion, and code generation. Despite these advances, detecting code vulnerabilities remains a challenging problem for LLMs. In-context learning (ICL) has emerged as an effective mechanism for improving model performance by providing a small number of labeled examples within the prompt. Prior work has shown, however, that the effectiveness of ICL depends critically on how these few-shot examples are selected. In this paper, we study two intuitive criteria for selecting few-shot examples for ICL in the context of code vulnerability detection. The first criterion leverages model behavior by prioritizing samples on which the LLM consistently makes mistakes, motivated by the intuition that such samples can expose and correct systematic model weaknesses. The second criterion selects examples based on semantic similarity to the query program, using k-nearest-neighbor retrieval to identify relevant contexts. We conduct extensive evaluations using open-source LLMs and datasets spanning multiple programming languages. Our results show that for Python and JavaScript, careful selection of few-shot examples can lead to measurable performance improvements in vulnerability detection. In contrast, for C and C++ programs, few-shot example selection has limited impact, suggesting that more powerful but also more expensive approaches, such as re-training or fine-tuning, may be required to substantially improve model performance.
title On the Difficulty of Selecting Few-Shot Examples for Effective LLM-based Vulnerability Detection
topic Software Engineering
Cryptography and Security
Machine Learning
url https://arxiv.org/abs/2510.27675