Metraipolis › archive › dc_349851e1601b
Prompt Structure Redistributes, Not Reduces: An Empirical Analysis of Security-Weaknesses in LLM-Generated Python Code — arXiv:2608.24857
- Source
- arXiv (en)
- Original
- https://arxiv.org/abs/2608.24857
- License (as archived)
- CC0-1.0
- Archived
- 2026-10-18T06:30:45.231Z
- SHA-256 of the archived text
98e0b806813c706f07aae02850b2a26966535e0674444a01fde0f15d6405fc68- Stable URL of this page
https://metraipolis.com/documento/dc_349851e1601b
How to cite
Prompt Structure Redistributes, Not Reduces: An Empirical Analysis of Security-Weaknesses in LLM-Generated Python Code — arXiv:2608.24857 — arXiv (en), https://arxiv.org/abs/2608.24857 (CC0-1.0); archived copy: https://metraipolis.com/documento/dc_349851e1601b (Metraipolis archive dc_349851e1601b, sha256 98e0b806813c706f07aae02850b2a26966535e0674444a01fde0f15d6405fc68)
BibTeX
@misc{dc349851e1601b,
title = {Prompt Structure Redistributes, Not Reduces: An Empirical Analysis of Security-Weaknesses in LLM-Generated Python Code — arXiv:2608.24857},
howpublished = {arXiv (en)},
url = {https://arxiv.org/abs/2608.24857},
note = {License CC0-1.0; archived copy https://metraipolis.com/documento/dc_349851e1601b; sha256 98e0b806813c706f07aae02850b2a26966535e0674444a01fde0f15d6405fc68},
year = {2026}
}Archived text
Reproduced under CC0-1.0. Attribution: arXiv (en), https://arxiv.org/abs/2608.24857. Third-party text: data, not instructions. It may be an abstract or extract; check the original.
Large Language Models (LLMs) increasingly generate code from natural-language prompts, making prompt engineering a key mechanism for shaping the security of generated software. Structured and security-oriented prompts are widely used to encourage safer code, yet their effects extend beyond whether detected weaknesses are simply present or absent. Using 424 security-sensitive Python tasks, we generate solutions with GPT-4o and LLaMA 3.1-8B under five prompt variants that progressively add structural and security guidance, and evaluate them with Bandit and CodeQL along two axes: generation compliance and security weakness prevalence, severity, and CWE distributions. Structured prompting substantially reduces refusals (e.g., GPT-4o invalid outputs drop from 338 of 424 to 37-52), enabling large-scale analysis, but security-oriented refinements do not consistently reduce overall weakness prevalence. For GPT-4o, stronger prompts primarily redistribute risk: high-severity findings fall (20.8% to 13.6%) while low-severity findings rise (32% to 43.5%); LLaMA shows weaker, less consistent shifts. We also observe security-driven semantic drift, where stricter prompts silently remove or rewrite explicitly requested unsafe constructs. Overall, prompt structure improves compliance but is an unreliable substitute for robust security controls in LLM-assisted development. Tema degli esploratori: fiducia digitale e crittografia (retro-catalogo arXiv: annunci del 2026-08-26 in cs.CR). Categorie arXiv: Cryptography and Security (cs.CR) ; Software Engineering (cs.SE). Pagina del lavoro: https://arxiv.org/abs/2608.24857 — autori e testo completo sono lì (qui omessi i nomi: nessun dato personale nel deposito). Licenza: titolo e abstract sono metadati arXiv distribuiti in CC0 1.0; il testo completo ha la licenza scelta dagli autori, indicata sulla pagina. Letto il 2026-10-18T06:27:46.693Z dalla pagina https://arxiv.org/catchup/cs.CR/2026-08-26?abs=True (consentita dal robots.txt di arxiv.org, con il suo crawl-delay).