Cited by 1Software Engineering ResearchSoftware Testing and Debugging TechniquesWeb Application Security Vulnerabilities

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

Open access
Hannan, Md Abdul, Ni, Ronghao, Zhang, Chi, Jia, Limin, Mangal, Ravi, Pasareanu, Corina S.·2026·Proceedings 2026 Workshop on LLM Assisted Security and Trust Exploration

Abstract

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 fewshot 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 retraining or fine-tuning, may be required to substantially improve model performance.

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Integrity signals

Registry

Crossref · 10.14722/last-x.2026.23025

Cites

0 citation errors · 0 not checkable

Statistics

Claims the paper makes

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Self-check

Percentages, sums and reported differences re-computed from the paper’s own numbers.

The self-check needs the paper’s full text.

Cites

The publisher hasn’t deposited this paper’s reference list.

Research works printed but not linked: 40

  1. J. Jiang, F. Wang, J. Shen, S. Kim, and S. Kim, "A survey on large language models for code generation," arXiv preprint arXiv:2406.00515, 2024. · arXiv
  2. X. Zhou, S. Cao, X. Sun, and D. Lo, "Large language model for vulnerability detection and repair: Literature review and the road ahead," ACM Transactions on Software Engineering and Methodology, vol. 34, no. 5, pp. 1-31, 2025.
  3. W. Sun, Y. Miao, Y. Li, H. Zhang, C. Fang, Y. Liu, G. Deng, Y. Liu, and Z. Chen, "Source code summarization in the era of large language models," in 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE), 2025, pp. 1882-1894.
  4. R. A. Husein, H. Aburajouh, and C. Catal, "Large language models for code completion: A systematic literature review," Computer Standards & Interfaces, vol. 92, p. 103917, 2025.
  5. Y. Wan, Z. Bi, Y. He, J. Zhang, H. Zhang, Y. Sui, G. Xu, H. Jin, and P. Yu, "Deep learning for code intelligence: Survey, benchmark and toolkit," ACM Computing Surveys, vol. 56, no. 12, pp. 1-41, 2024.
  6. T. Zheng, H. Liu, H. Xu, X. Chen, P. Yi, and Y. Wu, "Few-vuld: A few-shot learning framework for software vulnerability detection," Computers & Security, vol. 144, p. 103992, 2024.
  7. J. Lin and D. Mohaisen, "From large to mammoth: A comparative evaluation of large language models in vulnerability detection," in Proceedings of the 2025 Network and Distributed System Security Symposium (NDSS), 2025.
  8. Y. Ding, Y. Fu, O. Ibrahim, C. Sitawarin, X. Chen, B. Alomair, D. Wag- ner, B. Ray, and Y. Chen, "Vulnerability detection with code language models: How far are we?" in 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE). IEEE Computer Society, 2024, pp. 469-481.
  9. A. Khare, S. Dutta, Z. Li, A. Solko-Breslin, R. Alur, and M. Naik, "Understanding the effectiveness of large language models in detecting security vulnerabilities," in 2025 IEEE Conference on Software Testing, Verification and Validation (ICST). IEEE, 2025, pp. 103-114.
  10. S. Min, M. Lewis, H. Hajishirzi, and L. Zettlemoyer, "Noisy channel language model prompting for few-shot text classification," in Proceed- ings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 2022, pp. 5316-5330.
  11. S. Lipp, S. Banescu, and A. Pretschner, "An empirical study on the effectiveness of static c code analyzers for vulnerability detection," in Proceedings of the 31st ACM SIGSOFT international symposium on software testing and analysis, 2022, pp. 544-555.
  12. F. Marques, M. Ferreira, A. Nascimento, M. E. Coimbra, N. Santos, L. Jia, and J. Fragoso Santos, "Automated exploit generation for node. js packages," Proceedings of the ACM on Programming Languages, vol. 9, no. PLDI, pp. 1341-1366, 2025.
  13. V. J. Manès, H. Han, C. Han, S. K. Cha, M. Egele, E. J. Schwartz, and M. Woo, "The art, science, and engineering of fuzzing: A survey," IEEE Transactions on Software Engineering, vol. 47, no. 11, pp. 2312-2331, 2021.
  14. D. Cassel, W. T. Wong, and L. Jia, "Nodemedic: End-to-end analysis of node. js vulnerabilities with provenance graphs," in 2023 IEEE 8th European Symposium on Security and Privacy (EuroS&P). IEEE, 2023, pp. 1101-1127.
  15. P. Li, S. Yao, J. S. Korich, C. Luo, J. Yu, Y. Cao, and J. Yang, "Automated static vulnerability detection via a holistic neuro-symbolic approach," arXiv preprint arXiv:2504.16057, 2025. · arXiv
  16. Z. Li, D. Zou, S. Xu, X. Ou, H. Jin, S. Wang, Z. Deng, and Y. Zhong, "VulDeePecker: A deep learning-based system for vulnerability detec- tion," arXiv preprint arXiv:1801.01681, 2018. · arXiv
  17. D. Hin, A. Kan, H. Chen, and M. A. Babar, "Linevd: Statement-level vulnerability detection using graph neural networks," in Proceedings of the 19th international conference on mining software repositories, 2022, pp. 596-607.
  18. W. Melicher, C. Fung, L. Bauer, and L. Jia, "Towards a lightweight, hybrid approach for detecting dom xss vulnerabilities with machine learning," in Proceedings of the Web Conference 2021, ser. WWW '21, 2021.
  19. J. Nam and S. Kim, "Clami: Defect prediction on unlabeled datasets (t)," in 2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE). IEEE, 2015, pp. 452-463.
  20. N. Medeiros, N. Ivaki, P. Costa, and M. Vieira, "Vulnerable code detection using software metrics and machine learning," IEEE Access, vol. 8, pp. 219 174-219 198, 2020.
  21. Y. Zhou, S. Liu, J. Siow, X. Du, and Y. Liu, "Devign: Effective vul- nerability identification by learning comprehensive program semantics via graph neural networks," Advances in neural information processing systems, vol. 32, 2019.
  22. Y. Li, S. Wang, and T. N. Nguyen, "Vulnerability detection with fine- grained interpretations," in Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, 2021, pp. 292-303.
  23. B. Steenhoek, H. Gao, and W. Le, "Dataflow analysis-inspired deep learning for efficient vulnerability detection," in Proceedings of the 46th IEEE/ACM International Conference on Software Engineering, 2024, pp. 1-13.
  24. R. Croft, M. A. Babar, and M. M. Kholoosi, "Data quality for software vulnerability datasets," in 2023 IEEE/ACM 45th International Confer- ence on Software Engineering (ICSE). IEEE, 2023, pp. 121-133.
  25. A. S. Yadav and J. N. Wilson, "R+ r: Security vulnerability dataset quality is critical," in 2024 Annual Computer Security Applications Conference (ACSAC). IEEE, 2024, pp. 1047-1061.
  26. Y. Li, N. T. Bui, T. Zhang, M. Weyssow, C. Yang, X. Zhou, J. Jiang, J. Chen, H. Huang, H. H. Nguyen et al., "Out of distribution, out of luck: How well can llms trained on vulnerability datasets detect top 25 cwe weaknesses?" arXiv preprint arXiv:2507.21817, 2025. · arXiv
  27. H. Hanif and S. Maffeis, "Vulberta: Simplified source code pre-training for vulnerability detection," in 2022 International joint conference on neural networks (IJCNN). IEEE, 2022, pp. 1-8.
  28. B. Steenhoek, M. M. Rahman, R. Jiles, and W. Le, "An empirical study of deep learning models for vulnerability detection," in 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE). IEEE, 2023, pp. 2237-2248.
  29. Z. Li, D. Zou, S. Xu, H. Jin, Y. Zhu, and Z. Chen, "Sysevr: A framework for using deep learning to detect software vulnerabilities," IEEE Transactions on Dependable and Secure Computing, vol. 19, no. 4, pp. 2244-2258, 2021.
  30. T. Brown, B. Mann, N. Ryder, M. Subbiah, J. D. Kaplan, P. Dhariwal, A. Neelakantan, P. Shyam, G. Sastry, A. Askell et al., "Language mod- els are few-shot learners," Advances in neural information processing systems, vol. 33, pp. 1877-1901, 2020.
  31. G. Ramesh, M. Sahil, S. A. Palan, D. Bhandary, T. A. Ashok, J. Shreyas, and N. Sowjanya, "A review on nlp zero-shot and few-shot learning: methods and applications," Discover Applied Sciences, vol. 7, no. 9, pp. 1-22, 2025.
  32. J. Wei, X. Wang, D. Schuurmans, M. Bosma, F. Xia, E. Chi, Q. V. Le, D. Zhou et al., "Chain-of-thought prompting elicits reasoning in large language models," Advances in neural information processing systems, vol. 35, pp. 24 824-24 837, 2022.
  33. T. Bansal, R. Jha, and A. McCallum, "Learning to few-shot learn across diverse natural language classification tasks," arXiv preprint arXiv:1911.03863, 2019. · arXiv
  34. Z. Jiang, F. F. Xu, J. Araki, and G. Neubig, "How can we know what language models know?" Transactions of the Association for Computational Linguistics, vol. 8, pp. 423-438, 2020.
  35. O. Rubin, J. Herzig, and J. Berant, "Learning to retrieve prompts for in- context learning," in Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, 2022, pp. 2655-2671.
  36. A. Sabbatella, A. Ponti, I. Giordani, A. Candelieri, and F. Archetti, "Prompt optimization in large language models," Mathematics, vol. 12, no. 6, p. 929, 2024.
  37. Y. Lu, M. Bartolo, A. Moore, S. Riedel, and P. Stenetorp, "Fantastically ordered prompts and where to find them: Overcoming few-shot prompt order sensitivity," in Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 2022, pp. 8086-8098.
  38. Q. Guo, L. Wang, Y. Wang, W. Ye, and S. Zhang, "What makes a good order of examples in in-context learning," in Findings of the Association for Computational Linguistics: ACL 2024, 2024, pp. 14 892-14 904.
  39. R. Agarwal, A. Singh, L. Zhang, B. Bohnet, L. Rosias, S. Chan, B. Zhang, A. Anand, Z. Abbas, A. Nova et al., "Many-shot in-context learning," Advances in Neural Information Processing Systems, vol. 37, pp. 76 930-76 966, 2024.
  40. N. Risse, J. Liu, and M. Böhme, "Top score on the wrong exam: On benchmarking in machine learning for vulnerability detection," Proceedings of the ACM on Software Engineering, vol. 2, no. ISSTA, pp. 388-410, 2025.

Cited by

Sorted by citations

Authors
Hannan, M. A., Ni, R., Zhang, C., Jia, L., Mangal, R., & Pasareanu, C. S.
Affiliations
  • Carnegie Mellon University (US)
  • Colorado State University (US)
Venue
Proceedings 2026 Workshop on LLM Assisted Security and Trust Exploration
Published
2026
OpenAlex
W4415928556
Cited by
0
References
0
FWCI
0.00
Type
conference paper
Language
en
Open access
Locations
  • arXiv (Cornell University) (submittedVersion)
  • arXiv (Cornell University)
Funders
National Science Foundation (2504353, 2504354)
Topics
  • Physical Sciences › Computer Science › Information Systems › Software Engineering Research
  • Physical Sciences › Computer Science › Software › Software Testing and Debugging Techniques
  • Physical Sciences › Computer Science › Information Systems › Web Application Security Vulnerabilities
Keywords
code vulnerability detection, in-context learning, large language models, k-nearest neighbor search, semantic similarity, model weaknesses, Python, JavaScript, C/C++, programming languages

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review