The Impact of Few-Shot Examples for LLM-based Code Vulnerability Detection
| dc.contributor.author | Hannan, Md Abdul, author | |
| dc.contributor.author | Mangal, Ravi, advisor | |
| dc.contributor.author | Ghosh, Sudipto, committee member | |
| dc.contributor.author | Vijayasarathy, Leo, committee member | |
| dc.date.accessioned | 2026-08-24T10:38:31Z | |
| dc.date.issued | 2026 | |
| 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. | |
| dc.format.medium | born digital | |
| dc.format.medium | masters theses | |
| dc.identifier | Hannan_colostate_0053N_19738.pdf | |
| dc.identifier.uri | https://hdl.handle.net/10217/245339 | |
| dc.identifier.uri | https://doi.org/10.25675/3.027353 | |
| dc.language | English | |
| dc.language.iso | eng | |
| dc.publisher | Colorado State University. Libraries | |
| dc.relation.ispartof | 2020- | |
| 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. | |
| dc.subject | few-shot | |
| dc.subject | LLMs | |
| dc.subject | attribution | |
| dc.subject | Vulnerability | |
| dc.subject | LIG | |
| dc.title | The Impact of Few-Shot Examples for LLM-based Code Vulnerability Detection | |
| dc.type | Text | |
| dcterms.rights.dpla | 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). | |
| thesis.degree.discipline | Computer Science | |
| thesis.degree.grantor | Colorado State University | |
| thesis.degree.level | Masters | |
| thesis.degree.name | Master of Science (M.S.) |
Files
Original bundle
1 - 1 of 1
Loading...
- Name:
- Hannan_colostate_0053N_19738.pdf
- Size:
- 232.44 KB
- Format:
- Adobe Portable Document Format
