Benchmarking Prompt Engineering Techniques for Secure Code Generation with GPT Models
On the map: LLM reasoning → Reasoning for agents, planning and code
Abstract (arXiv)
Prompt engineering reduces reasoning mistakes in Large Language Models (LLMs). However, its effectiveness in mitigating vulnerabilities in LLM-generated code remains underexplored. To address this gap, we implemented a benchmark to automatically assess the impact of various prompt engineering strategies on code security. Our benchmark leverages two peer-reviewed prompt datasets and employs static scanners to evaluate code security at scale. We tested multiple prompt engineering techniques on GPT-3.5-turbo, GPT-4o, and GPT-4o-mini. Our results show that for GPT-4o and GPT-4o-mini, a security-focused prompt prefix can reduce the occurrence of security vulnerabilities by up to 56%. Additionally, all tested models demonstrated the ability to detect and repair between 41.9% and 68.7% of vulnerabilities in previously generated code when using iterative prompting techniques. Finally, we introduce a "prompt agent" that demonstrates how the most effective techniques can be applied in real-world development workflows.
Key facts. Cited by 12 papers in the map (data through 7 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 10 of its 15 references that are in the map. First posted on arXiv 9 Feb 2025.
Builds on
10 of 15 references.
References · 10
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2024A Systematic Survey of Prompt Engineering in Large Language Models: Techniques and Applicationscited by 428
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
- 2023Purple Llama CyberSecEval: A Secure Coding Benchmark for Language Modelscited by 130
- 2023How Secure is Code Generated by ChatGPT?cited by 77
- 2023LLMSecEval: A Dataset of Natural Language Prompts for Security Evaluationscited by 58
- 2024Prompting Techniques for Secure Code Generation: A Systematic Investigationcited by 33
- 2024LLM Security Guard for Codecited by 15
- 2024ChatGPT's Potential in Cryptography Misuse Detection: A Comparative Analysis with Static Analysis Toolscited by 4
- 2024Time to Separate from StackOverflow and Match with ChatGPT for Encryptioncited by 3
Built on by
Citing papers per year: 2025: 4; 2026: 8.
12 papers.
- 2025Security Bug Report Prediction Within and Across Projects: A Comparative Study of BERT and Random Forestcited by 2
- 2025When "Correct" Is Not Safe: Can We Trust Functionally Correct Patches Generated by Code Agents?cited by 2
- 2026Adaptive Hierarchical Evaluation of LLMs and SAST tools for CWE Prediction in Pythoncited by 1
- 2026Evaluating Large Language Models for Security Bug Report Predictioncited by 1
- 2026Enhancing Reliability in LLM-Based Secure Code Generationcited by 1
- 2025Poisoned Source Code Detection in Code Modelscited by 0
- 2025A Dataset and Preliminary Study of Using GPT-5 for Code-change Impact Analysiscited by 0
- 2026From Data Leak to Secret Misses: The Impact of Data Leakage on Secret Detection Modelscited by 0
- 2026A Quasi-Experimental Developer Study of Security Training in LLM-Assisted Web Application Developmentcited by 0
- 2026Understanding the Impact of AI Code Assistants on Security API Usage: An Empirical Studycited by 0
- 2026The Illusion of Secure LLM Code: Closing the Security Gap via Iterative Repromptingcited by 0
- 2026MACGen: Toward Functionally Correct and Secure Code Generation via Multi-Agent Collaborationcited by 0
- 2026MACGen: Toward Functionally Correct and Secure Code Generation via Multi-Agent Collaboration26 Aug 2026
- 2026The Illusion of Secure LLM Code: Closing the Security Gap via Iterative Reprompting26 Jul 2026
- 2026Understanding the Impact of AI Code Assistants on Security API Usage: An Empirical Study13 Jul 2026
- 2026Enhancing Reliability in LLM-Based Secure Code Generation22 May 2026
- 2026A Quasi-Experimental Developer Study of Security Training in LLM-Assisted Web Application Development20 Apr 2026
- 2026From Data Leak to Secret Misses: The Impact of Data Leakage on Secret Detection Models30 Jan 2026
- 2026Evaluating Large Language Models for Security Bug Report Prediction30 Jan 2026
- 2026Adaptive Hierarchical Evaluation of LLMs and SAST tools for CWE Prediction in Python4 Jan 2026
- 2025A Dataset and Preliminary Study of Using GPT-5 for Code-change Impact Analysis22 Dec 2025
- 2025When "Correct" Is Not Safe: Can We Trust Functionally Correct Patches Generated by Code Agents?15 Oct 2025
- 2025Security Bug Report Prediction Within and Across Projects: A Comparative Study of BERT and Random Forest28 Apr 2025
- 2025Poisoned Source Code Detection in Code Models19 Feb 2025
Similar, not cited
Close in wording, no citation either way
- 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
- 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
- 2025Is Your Prompt Poisoning Code? Defect Induction Rates and Security Mitigation Strategies
- 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimization
- 2026PromptAudit: Auditing Prompt Sensitivity in LLM-Based Vulnerability Detection
- 2024The Impact of Prompt Programming on Function-Level Code Generation
- 2024Can LLM Prompting Serve as a Proxy for Static Analysis in Vulnerability Detection
- 2025Rethinking the Evaluation of Secure Code Generation