mlsanityData to 7 Oct 2026

Benchmarking Prompt Engineering Techniques for Secure Code Generation with GPT Models

arXiv 2502.06039 ↗First posted 9 Feb 2025cs.SE cs.AI cs.CRcited by 12

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

  1. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  2. 2024A Systematic Survey of Prompt Engineering in Large Language Models: Techniques and Applicationscited by 428
  3. 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
  4. 2023Purple Llama CyberSecEval: A Secure Coding Benchmark for Language Modelscited by 130
  5. 2023How Secure is Code Generated by ChatGPT?cited by 77
  6. 2023LLMSecEval: A Dataset of Natural Language Prompts for Security Evaluationscited by 58
  7. 2024Prompting Techniques for Secure Code Generation: A Systematic Investigationcited by 33
  8. 2024LLM Security Guard for Codecited by 15
  9. 2024ChatGPT's Potential in Cryptography Misuse Detection: A Comparative Analysis with Static Analysis Toolscited by 4
  10. 2024Time to Separate from StackOverflow and Match with ChatGPT for Encryptioncited by 3

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 4; 2026: 8.

12 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
  2. 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
  3. 2025Is Your Prompt Poisoning Code? Defect Induction Rates and Security Mitigation Strategies
  4. 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimization
  5. 2026PromptAudit: Auditing Prompt Sensitivity in LLM-Based Vulnerability Detection
  6. 2024The Impact of Prompt Programming on Function-Level Code Generation
  7. 2024Can LLM Prompting Serve as a Proxy for Static Analysis in Vulnerability Detection
  8. 2025Rethinking the Evaluation of Secure Code Generation