On the Difficulty of Selecting Few-Shot Examples for Effective LLM-based Vulnerability Detection
Not on the map. Why?
Abstract (arXiv)
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.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 53 of its 74 references that are in the map. First posted on arXiv 31 Oct 2025.
Builds on
53 of 74 references.
References · 53
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2024The Llama 3 Herd of Modelscited by 14,715
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 14,132
- 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,459
- 2025Qwen3 Technical Reportcited by 8,820
- 2024Qwen2.5 Technical Reportcited by 4,942
- 2023Qwen Technical Reportcited by 3,344
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2024Qwen2 Technical Reportcited by 2,120
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
- 2024Qwen2.5-Coder Technical Reportcited by 1,203
- 2021What Makes Good In-Context Examples for GPT-3?cited by 1,195
38 more
- 2021Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order Sensitivitycited by 1,135
- 2019How Can We Know What Language Models Know?cited by 959
- 2023DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelinescited by 832
- 2024A Survey on Large Language Models for Code Generationcited by 658
- 2023Automatic Prompt Optimization with "Gradient Descent" and Beam Searchcited by 653
- 2021Learning To Retrieve Prompts for In-Context Learningcited by 648
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 609
- 2025GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learningcited by 542
- 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 272
- 2024Many-Shot In-Context Learningcited by 206
- 2021Noisy Channel Language Model Prompting for Few-Shot Text Classificationcited by 165
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
- 2023ExpertPrompting: Instructing Large Language Models to be Distinguished Expertscited by 142
- 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 139
- 2023DiverseVul: A New Vulnerable Source Code Dataset for Deep Learning Based Vulnerability Detectioncited by 102
- 2018SySeVR: A Framework for Using Deep Learning to Detect Software Vulnerabilitiescited by 92
- 2024Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAGcited by 68
- 2018The Art, Science, and Engineering of Fuzzing: A Surveycited by 62
- 2023Understanding the Effectiveness of Large Language Models in Detecting Security Vulnerabilitiescited by 59
- 2019Learning to Few-Shot Learn Across Diverse Natural Language Classification Taskscited by 57
- 2021Vulnerability Detection with Fine-grained Interpretationscited by 56
- 2022VulBERTa: Simplified Source Code Pre-Training for Vulnerability Detectioncited by 51
- 2023Data Quality for Software Vulnerability Datasetscited by 51
- 2023kNN Prompting: Beyond-Context Learning with Calibration-Free Nearest Neighbor Inferencecited by 47
- 2022An Empirical Study of Deep Learning Models for Vulnerability Detectioncited by 46
- 2024Large Language Model for Vulnerability Detection and Repair: Literature Review and the Road Aheadcited by 42
- 2022LineVD: Statement-level Vulnerability Detection using Graph Neural Networkscited by 35
- 2024CodeXEmbed: A Generalist Embedding Model Family for Multiligual and Multi-task Code Retrievalcited by 34
- 2024Source Code Summarization in the Era of Large Language Modelscited by 31
- 2024Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuningcited by 30
- 2024Top Score on the Wrong Exam: On Benchmarking in Machine Learning for Vulnerability Detectioncited by 28
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkitcited by 22
- 2022Dataflow Analysis-Inspired Deep Learning for Efficient Vulnerability Detectioncited by 19
- 2024Security Vulnerability Detection with Multitask Self-Instructed Fine-Tuning of Large Language Modelscited by 14
- 2025Maestro: Joint Graph & Config Optimization for Reliable AI Agentscited by 9
- 2025OptiSeq: Ordering Examples On-The-Fly for In-Context Learningcited by 6
- 2025Out of Distribution, Out of Luck: How Well Can LLMs Trained on Vulnerability Datasets Detect Top 25 CWE Weaknesses?cited by 6
- 2025R+R: Security Vulnerability Dataset Quality Is Criticalcited by 3
50 most cited of 53 All 53 (JSON)
Built on by
Not cited yet.