Back to search

Colorado State University. Libraries

The impact of few-shot examples for LLM-based code vulnerability detection

Abstract

dc:description.abstract

Large language models (LLMs) have shown promise for detecting software vulnerabilities through in-context learning (ICL), where a small number of labeled examples are provided in the prompt to guide model predictions. However, the effectiveness of ICL depends critically on how these few-shot examples are selected, and little is studied about what these models actually attend to when making their decisions. This work addresses both gaps directly. First, how should those few-shot examples be selected to maximize detection performance? Second, when the model makes correct predictions, is it actually focusing on the right tokens of the vulnerable code? The first part studies two selection criteria: Learn-from-Mistakes (LFM), which prioritizes examples on which the model consistently makes errors, and Learn-from-Nearest-Neighbors (LFNN), which retrieves semantically similar examples using a code embedding model. We evaluate these methods and three combined strategies on five datasets spanning C/C++, Python, and JavaScript, using Qwen2.5-Coder-7B-Instruct, Gemma-3-4b-it, and GPT-5-mini. As a single method, LFNN consistently improves performance on Python and JavaScript, while C/C++ datasets remain resistant to few-shot adaptation. Combined methods showed the best performance overall. The second part takes the LFNN pipeline and Qwen model, and audits its internal attribution behavior using Layer Integrated Gradients (LIG). Our experiments reveal that among the top-50 tokens identified by the attribution method, 40 to 52 percent belong to the injected few-shot examples. More strikingly, fewer than 2 percent of those top-50 tokens correspond to actual vulnerable tokens, even on samples the model predicted correctly. These findings show that even when LFNN improves detection accuracy, gradient-based attributions are not always grounded in the actual vulnerable code tokens, revealing a gap between performance and reliability in LLM-based code vulnerability detection.

Degree

thesis:*
Name thesis:degree_name
Master of Science (M.S.)
Level thesis:degree_level
Masters
Discipline thesis:degree_discipline
Computer Science
Grantor dc:publisher
Colorado State University. Libraries
Year dc:date.issued
2026

Author and committee

dc:creator, dc:contributor.*
Authors dc:creator
  • Hannan, Md Abdul, author
  • Mangal, Ravi, advisor
  • Ghosh, Sudipto, committee member
  • Vijayasarathy, Leo, committee member

Subjects

dc:subject × 5

Rights

dc:rights
Statement dc:rights
  • Copyright and other restrictions may apply. User is responsible for compliance with all applicable laws. For information about copyright law, please see https://libguides.colostate.edu/copyright.
  • This Item is protected by copyright and/or related rights (https://rightsstatements.org/vocab/InC/1.0/). You are free to use this Item in any way that is permitted by the copyright and related rights legislation that applies to your use. For other uses you need to obtain permission from the rights-holder(s).
Language dc:language.iso
eng, English

Identifiers

dc:identifier.*

Chain of custody

source
Harvested from
Colorado State University
Base URL
api.mountainscholar.org/server/oai/request
Last updated
2026-11-19
Source record
OAI-PMH GetRecord
citation

Hannan, Md Abdul, author; Mangal, Ravi, advisor; Ghosh, Sudipto, committee member; Vijayasarathy, Leo, committee member. The impact of few-shot examples for LLM-based code vulnerability detection. Masters thesis, Colorado State University. Libraries, 2026. https://hdl.handle.net/10217/245339