arXiv:2610.08405cs.SEOct 2026

Manuscript Offprint

arXiv:2610.08405

Learning from Failures: A Failure-Driven Prompt Refinement for LLM-Based Vulnerability Analysis

Mandana Ghadamian, David Mohaisen

Mandana Ghadamian and David Mohaisen

University of Central Florida, Orlando, FL 32816, USA

{mandana.ghadamian,mohaisen}@ucf.edu

Abstract. Large Language Models have emerged as promising tools for software vulnerability analysis, but their effectiveness depends heavily on prompt design. Existing research primarily compares prompting strategies using aggregate performance metrics, providing limited insight into why models fail or how prompts can be improved systematically. We propose Failure-Driven Prompt Refinement (FDPR), a methodology that analyzes recurring model failures to guide evidence-based prompt refinement. Using the Damn Vulnerable Java Application (DVJA), we identify recurring failure modes, including false positives, false negatives, unsupported reasoning, and CWE misclassification, and translate them into targeted prompt refinements. We then evaluate the resulting prompt on the Juliet Test Suite and perform cross-model validation to assess generalizability. The results show that failure-driven refinement improves the reliability of LLM-based vulnerability analysis while yielding reusable prompt design principles. More broadly, this work demonstrates that recurring model failures provide a principled foundation for prompt engineering, enabling the systematic development of more reliable LLM-based vulnerability analysis systems.

1 Introduction

Software vulnerabilities remain a primary cause of security breaches [23,13], making accurate and scalable vulnerability detection a fundamental challenge in secure software development. Traditional static and dynamic analysis techniques improve software assurance but often fail to detect vulnerabilities that require semantic understanding, complex program context, or developer intent [31]. Recent advances in LLMs have shown strong capabilities in program comprehension, code generation, debugging, and vulnerability analysis, suggesting that they can complement conventional techniques by reasoning about source code using learned programming knowledge [25,3,17]. Consequently, LLM-assisted vulnerability analysis has become an active research area.

Despite this progress, deploying LLMs in security-critical workflows remains challenging [14][14]. Vulnerability analysis requires recognizing security-relevant patterns and producing evidence-based conclusions supported by the analyzed program [24][24]. In practice, LLMs hallucinate vulnerabilities, generate unsupported reasoning [28][28], misclassify Common Weakness Enumeration (CWE) categories [24][24], and overgeneralize from superficial code patterns [11][11]. These limitations reduce analyst trust, increase verification effort, and hinder the practical adoption of LLM-based vulnerability analysis.

Recent work has explored prompt engineering strategies for software vulnerability detection, including zero-shot prompting, few-shot prompting, role-based instructions, structured output constraints, and domain-specific context [14][14]. These studies consistently demonstrate that prompt design substantially affects model performance [31,4][31,4].

M. Ghadamian and D. Mohaisen

However, prompt refinement remains largely empirical. Existing approaches typically compare prompt variants using aggregate metrics such as accuracy, precision, recall, and F1-score [1]. While these metrics quantify overall performance, they provide limited insight into why models fail. Consequently, false positives, false negatives, unsupported reasoning, hallucinated evidence, and incorrect CWE assignments are treated as evaluation outcomes rather than engineering signals for systematic prompt refinement.

This limitation is reflected in inconsistent findings. Studies of prompting for software vulnerability detection report conflicting results for few-shot prompting, role prompting, and contextual guidance [16]. Some report substantial gains from few-shot prompting [8], whereas others find marginal improvements or degraded performance relative to zero-shot prompting [19]. Similar inconsistencies arise for other prompting strategies [4,1]. These results suggest that prompt effectiveness depends on interactions among the model, dataset, task, and evaluation method, limiting the generalizability of benchmark-based guidelines [14]. We therefore ask three research questions: RQ1: Can recurring LLM failure patterns be systematically identified and organized to reveal prompt weaknesses in software vulnerability analysis? RQ2: Can iterative failure-driven prompt refinement improve the reliability and accuracy of LLM-based vulnerability detection? RQ3: What prompt design principles emerge from recurring failures, and do they generalize beyond the prompt-development dataset?

To answer these questions, we propose Failure-Driven Prompt Refinement (FDPR), a systematic, evidence-driven methodology for prompt engineering. FDPR identifies recurring failures, infers their causes, organizes them into a taxonomy, prioritizes them by their impact on analyst trust and system reliability, and translates them into targeted prompt revisions. Iterative application of this process produces reusable prompt design principles that improve the reliability of LLM-based vulnerability analysis.

We evaluate FDPR for Java vulnerability detection using a two-stage design. We first refine prompts on the Damn Vulnerable Java Application (DVJA), enabling detailed analysis of model behavior and recurring failure patterns. We then evaluate the refined prompt on the Juliet Test Suite, a substantially larger benchmark spanning diverse CWE categories, to assess generalization beyond the development dataset. Our results show that FDPR substantially reduces unreliable vulnerability reports and shifts the remaining errors from unsupported reasoning to taxonomy-level classification errors. The contributions of this paper are as follows:

  1. Failure-Driven Prompt Refinement. We introduce FDPR, a systematic methodology for improving prompts through iterative analysis of recurring LLM failures. FDPR combines structured failure analysis with evidence-driven prompt refinement, translating recurring failure patterns into targeted prompt modifications.

  2. Empirical Validation. We develop FDPR using the Damn Vulnerable Java Application (DVJA) and evaluate the resulting prompt on the Juliet Test Suite. The results demonstrate that systematic failure analysis improves the reliability of LLM-based vulnerability analysis while generalizing beyond the development benchmark.

  3. Reusable Design Principles. We derive reusable prompt design principles, including evidence-based reasoning, context-aware analysis, explicit uncertainty handling, and structured vulnerability classification. Although for software vulnerability, these principles may generalize to other LLM-based software engineering tasks.

Figure

Fig. 1. Evolution of zero-shot, few-shot, and chain-of-thought prompting techniques relevant to LLM-based software vulnerability detection, from their foundational general-purpose formulations to increasingly specialized adaptations for this task.

References (32)