Security-Oriented Prompts Redistribute Rather Than Reduce Vulnerabilities in LLM-Generated Python, and Silently Rewrite Requested Code
Across 424 security-sensitive Python tasks generated by GPT-4o and LLaMA 3.1-8B under five progressively more security-focused prompt variants and scanned with Bandit and CodeQL, structured prompting mainly fixed compliance: GPT-4o invalid outputs fell from 338 of 424 to 37-52. Overall weakness prevalence did not consistently drop. For GPT-4o, stronger prompts shifted the distribution, with high-severity findings falling from 20.8% to 13.6% while low-severity findings rose from 32% to 43.5%; LLaMA's shifts were weaker and less consistent. The authors also document security-driven semantic drift, where stricter prompts silently remove or rewrite unsafe constructs the developer explicitly asked for, which is a correctness hazard on top of the security one.
↳ Follow the thread