Single-character prompt changes can turn LLM-generated code insecure
Minor prompt perturbations can flip LLM-generated code from secure to vulnerable
AI/ML arXiv 28 May 2026 Measurement Simulation evidence
Published as “Minimal Prompt Perturbations Lead to Code Vulnerabilities: Prompt Fragility and Hidden-State Signals in Coding LLMs”
Why it matters
Even trivial prompt edits can introduce exploitable bugs, suggesting that developers and toolchains need automated checks or guardrails to catch security regressions before code is emitted.
Summary
Single-character prompt mutations can flip LLM-generated code from secure to vulnerable, with input-handling flaws being more predictable (mean AUC 0.753) than secure-defaults flaws (mean AUC 0.674). The authors evaluated three open-weight coding models across five languages using the CWEval benchmark and found that mutations frequently degrade both functionality and security, especially for CodeLlama and DeepSeek-Coder. Probing the prompt-end hidden states yields only modest predictive power (average AUC ~0.70), indicating limited ability to pre-empt insecure generations.
What they found 3
- Single-character prompt changes can turn secure code into vulnerable code.
“We apply token-level mutations to prompts across three models and five programming languages, and show that mutations as small as a single-character change can flip generated code from secure to vulnerable.”
- Input-handling vulnerabilities are more predictable from hidden states than secure-defaults vulnerabilities.
“Input-handling vulnerabilities, where the model omits validation or sanitization, are more predictable (mean AUC 0.753) than secure-defaults vulnerabilities, where insecure code stems from one local choice such as a weak algorithm or unsafe parameter (mean AUC 0.674).”
- Prompt-end hidden states provide only modest prediction of security outcomes.
“The mean held-out test AUC is approximately 0.70 for each model, with no systematic gap between the two targets.”
Caveats 7
- The probe AUC of ~0.70 indicates limited predictive power, undercutting the promise of reliable pre-generation detection.
- Quote: "The mean held-out test AUC is approximately 0.70 for each model, with no systematic gap between the two targets."
- Mutations can also improve security in some cases, not only degrade it.
- Quote: "Blue bars (improvements) average over CWEs whose original failed the metric; red bars (deteriorations) over CWEs whose original passed."
- Our findings rest on open-weight, code-specialized models in the 30B-70B range, with a supplementary analysis on two further models (gpt-oss (120B) and Qwen2.5-Coder (3B)). We were unable to evaluate the leading closed-source models or the largest open coding models, as our design requires generating and scoring many thousands of completions per model and extracting per-layer hidden states for probing.
- Our probing analysis relies on a single benchmark and therefore on a limited set of CWEs and task specifications.
- The partition of CWEs into the inputhandling and secure-defaults families is performed manually, on the basis of each vulnerability’s canonical fix.
What’s new here 4
- First systematic study of how minimal prompt perturbations affect security of generated code.
- Uses a joint functional-and-security benchmark (CWEval) rather than separate evaluations.
- Introduces probing of prompt-end hidden states to predict vulnerability before generation.
- Distinguishes two vulnerability families (input-handling vs. secure-defaults) with differing predictability.