← Lab /Software

Prompt syntax significantly changes security of code generated by open LLMs

Specific syntactic elements and their placement in prompts affect the likelihood of generating insecure code

Software arXiv 17 Jul 2026 Measurement Prototype evidence

Published as “The Language of Security: How Prompt Syntax Shapes Secure Code Generation in Open LLMs”

Why it matters

Practitioners should preserve WHNP/WHADVP clauses and avoid shortening prompts, as their removal can double the chance of generating vulnerable code.

Summary

Specific syntactic constituents and their position in prompts dramatically affect the security of code generated by open-source LLMs, with risk ratios up to 2.24 and vulnerability rates up to 100% for certain edits. The authors support this with large-scale experiments (4,320 generated snippets per model/language) across three models and three languages, statistical significance testing, and a replication package. However, baseline and permutation vulnerability rates are often similar, and the effect size varies by language.

What they found 2

  1. Removing the opening sentence (Sentence Index 0) significantly raises vulnerability rates across all models.

    “removals at Sentence Index 0 significantly increased vulnerability rates across all models, with RR ≈1.61 (Qwen, p = 0.027), RR ≈2.31 (Phi-4, p = 0.001), and RR ≈1.69 (Athene, p = 0.023).”

  2. Interrogative/relative constituents (WHADVP) are the most security-sensitive, yielding high risk ratios in Python.

    “WHADVP (p=3.838e-04, RR=1.88)”

Caveats 5

  • In Python, where effects were most pronounced, the permutation set exhibited a lower overall vulnerability incidence than the baseline (up to 7%).
  • Vulnerability rates between baseline and permutation prompts were generally similar.
  • Our scenarios, prompts, and analyses target function-level completions in English across a limited set of programming languages and open models. Results may not generalize to other prompt styles, natural or programming languages, larger/proprietary systems, or project-scale contexts.
  • different strategies (e.g., dependency-based or semantic role-based) could yield different effects.
  • While CodeQL is a static analyzer used at scale, any static analysis can miss issues (false negatives) or surface non-exploitable findings (false positives).

What’s new here 4

  • Fine-grained analysis of prompt syntax by systematically removing individual syntactic constituents.
  • Parser-driven generation of minimally altered prompt variants to enable causal inference.
  • Cross-model (Qwen, Phi-4, Athene) and cross-language (C, Java, Python) evaluation on open-source LLMs.
  • Public release of the perturbed prompt dataset and full replication package.