An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
Kharma, Mohammed, Sabbah, Ahmed, Alkhanafseh, Mohammad, Hammoudeh, Mohammad, Mohaisen, David
–arXiv.org Artificial Intelligence
They offer clear benefits in reducing development effort and speeding up prototyping, but their output is not always reliable (Kharma et al. 2026). In particular, LLM-generated code often introduces security weaknesses that compromise reliability. Our evaluation shows that the most frequent issues involve inadequate input validation, misuse of cryptographic functions, and unsafe memory handling, aligned with well-known classes in the Common Weakness Enumeration (CWE). These weaknesses are non-trivial because they appear even in simple programming tasks, and their impact differs depending on the LLM, the programming language, and the prompting strategy (Perry et al. 2023; Khoury et al. 2023). Prompt strategies are used to guide LLMs toward more accurate or stylistically consistent results. Prior work has shown that prompt design can improve accuracy, reasoning, and code readability, but its effect on the security properties of generated code has received little systematic attention. Most studies emphasize functional correctness, leaving open an important question: How do different prompt engineering strategies affect the frequency and severity of security weaknesses in LLM-generated code across multiple programming languages? By examining this relationship, we aim to identify prompting approaches that consistently reduce vulnerabilities and improve the overall security quality of LLM-generated code. To explore this question, we evaluate several widely used LLMs (claude-3.5,
arXiv.org Artificial Intelligence
May-26-2026
- Country:
- North America > United States (0.67)
- Asia > Middle East
- Saudi Arabia (0.28)
- Genre:
- Research Report
- New Finding (1.00)
- Experimental Study > Negative Result (1.00)
- Research Report
- Industry:
- Information Technology > Security & Privacy (1.00)
- Technology: