An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
Not on the map. Why?
Abstract (arXiv)
The growing use of Large Language Models (LLMs) for automated code generation has enhanced software development efficiency, but often at the cost of security. Generated code frequently overlooks critical concerns, leaving it vulnerable to issues such as weak encryption and improper input validation. To investigate this problem, we present a comprehensive empirical evaluation of the security quality of LLM-generated code across five LLMs and four programming languages (Java, C++, C, and Python), examining the impact of multiple prompt engineering methods. We introduce a weaknesses-aware zero-shot chain-of-thought (WA-0CoT) prompting strategy that enriches prompts with security context using CWE mappings to guide model reasoning. Our empirical analysis, supported by chi-square tests, finds no statistically significant reductions in vulnerability frequency or density across prompt methods. However, prompting strategies, including WA-0CoT, systematically influence the compositional distribution of CWE categories, with effects varying by programming language. These findings suggest that while security-aware prompting alters the structure of generated weaknesses, prompt engineering alone is insufficient to reliably reduce overall vulnerability levels. The results highlight the importance of language-aware and model-aware prompt design when evaluating the security properties of LLM-generated code.
Key facts. No citing papers in the map yet (data through 7 Oct 2026). Builds on 13 of its 30 references that are in the map. First posted on arXiv 22 May 2026.
Builds on
13 of 30 references.
References · 13
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023Self-Refine: Iterative Refinement with Self-Feedbackcited by 3,317
- 2023Language Models can Solve Computer Taskscited by 371
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
- 2021Cutting Down on Prompts and Parameters: Simple Few-Shot Learning with Language Modelscited by 139
- 2020You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completioncited by 112
- 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 87
- 2023How Secure is Code Generated by ChatGPT?cited by 77
- 2023Evaluating the Code Quality of AI-Assisted Code Generation Tools: An Empirical Study on GitHub Copilot, Amazon CodeWhisperer, and ChatGPTcited by 71
- 2024Why Does the Effective Context Length of LLMs Fall Short?cited by 60
- 2024Prompting Techniques for Secure Code Generation: A Systematic Investigationcited by 33
- 2025Security and Quality in LLM-Generated Code: A Multi-Language, Multi-Model Analysiscited by 18
1 more
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
- 2026Enhancing Reliability in LLM-Based Secure Code Generation
- 2025Benchmarking Prompt Engineering Techniques for Secure Code Generation with GPT Models
- 2025Rethinking the Evaluation of Secure Code Generation
- 2025Is Your Prompt Poisoning Code? Defect Induction Rates and Security Mitigation Strategies
- 2024The Impact of Prompt Programming on Function-Level Code Generation
- 2026Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-based Code Generation ↗
- 2025When Code Crosses Borders: A Security-Centric Study of LLM-based Code Translation ↗