Guiding AI to Fix Its Own Flaws: An Empirical Study on LLM-Driven Secure Code Generation
Not on the map. Why?
Abstract (arXiv)
Large Language Models have become powerful tools for programming. However, they often overlook essential security practices, producing insecure code with vulnerabilities. Despite this risk, existing work offers limited guidance on steering LLMs toward secure code generation and lacks systematic analysis of how effectively LLMs repair vulnerable code. In this work, we investigate how LLMs can be guided to prevent and repair security vulnerabilities during code generation. Specifically, we examine whether self-generated vulnerability hints help models avoid insecure code, and evaluate how different feedback levels influence post-hoc vulnerability repair. Our study considers proprietary and open-weight models across multiple scales and uses established benchmarks covering diverse vulnerability types. Our results show that self-generated vulnerability hints meaningfully reduce insecure code, with effectiveness depending strongly on relevance and preciseness. We further find that more directive hints, which name the target weakness, explain how it could arise in the task, and specify how to avoid it, more effectively prevent vulnerable code. For post-hoc vulnerability repair, raw detection-tool feedback improves security across all models, while detailed, actionable explanations provide further gains on two of the three benchmarks, especially for models with stronger instruction-following capabilities. Yet, this explained feedback does not consistently outperform the raw feedback for the benchmark containing real-world tasks triggering multiple weaknesses.
Key facts. Cited by 13 papers in the map (data through 14 Oct 2026). First posted on arXiv 28 Jun 2025.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2025: 2; 2026: 11.
13 papers.
Sort:
By area:
- 2025When Developer Aid Becomes Security Debt: A Systematic Analysis of Insecure Behaviors in LLM Coding Agentscited by 8
- 2026How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Testcited by 4
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregationcited by 2
- 2025From Prompt to Product: A Human-Centered Benchmark of Agentic App Generation Systemscited by 1
- 2026Adaptive Hierarchical Evaluation of LLMs and SAST tools for CWE Prediction in Pythoncited by 1
- 2026Surgical Repair of Insecure Code Generation in LLMscited by 1
- 2026LLMs + Security = Troublecited by 0
- 2026Why Do Large Language Models Generate Harmful Content?cited by 0
- 2026Quality and Security Signals in AI-Generated Python Refactoring Pull Requestscited by 0
- 2026Security of LLM-generated Code: A Comparative Analysiscited by 0
- 2026From Evaluation to Optimisation: Hierarchy-Aware Training Signals for CWE Prediction in Pythoncited by 0
- 2026Tool-Guided Retrieval-Augmented Repair for Securing LLM-Generated C Codecited by 0
1 more
- 2026Interpreting and Steering for Safe and Correct Code Generation30 Aug 2026
- 2026From Evaluation to Optimisation: Hierarchy-Aware Training Signals for CWE Prediction in Python23 Jul 2026
- 2026Tool-Guided Retrieval-Augmented Repair for Securing LLM-Generated C Code21 Jul 2026
- 2026Security of LLM-generated Code: A Comparative Analysis21 May 2026
- 2026Quality and Security Signals in AI-Generated Python Refactoring Pull Requests20 May 2026
- 2026Surgical Repair of Insecure Code Generation in LLMs17 Apr 2026
- 2026Why Do Large Language Models Generate Harmful Content?13 Apr 2026
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation10 Apr 2026
- 2026LLMs + Security = Trouble9 Feb 2026
- 2026How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Test11 Jan 2026
- 2026Adaptive Hierarchical Evaluation of LLMs and SAST tools for CWE Prediction in Python4 Jan 2026
- 2025From Prompt to Product: A Human-Centered Benchmark of Agentic App Generation Systems19 Dec 2025
- 2025When Developer Aid Becomes Security Debt: A Systematic Analysis of Insecure Behaviors in LLM Coding Agentscited by 8
- 2025From Prompt to Product: A Human-Centered Benchmark of Agentic App Generation Systemscited by 1
- 2026Quality and Security Signals in AI-Generated Python Refactoring Pull Requestscited by 0
- 2026Quality and Security Signals in AI-Generated Python Refactoring Pull Requests20 May 2026
- 2025From Prompt to Product: A Human-Centered Benchmark of Agentic App Generation Systems19 Dec 2025
- 2025When Developer Aid Becomes Security Debt: A Systematic Analysis of Insecure Behaviors in LLM Coding Agents12 Jul 2025
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregationcited by 2
- 2026Adaptive Hierarchical Evaluation of LLMs and SAST tools for CWE Prediction in Pythoncited by 1
- 2026Surgical Repair of Insecure Code Generation in LLMscited by 1
- 2026LLMs + Security = Troublecited by 0
- 2026Security of LLM-generated Code: A Comparative Analysiscited by 0
- 2026From Evaluation to Optimisation: Hierarchy-Aware Training Signals for CWE Prediction in Pythoncited by 0
- 2026Tool-Guided Retrieval-Augmented Repair for Securing LLM-Generated C Codecited by 0
- 2026Interpreting and Steering for Safe and Correct Code Generationcited by 0
- 2026Interpreting and Steering for Safe and Correct Code Generation30 Aug 2026
- 2026From Evaluation to Optimisation: Hierarchy-Aware Training Signals for CWE Prediction in Python23 Jul 2026
- 2026Tool-Guided Retrieval-Augmented Repair for Securing LLM-Generated C Code21 Jul 2026
- 2026Security of LLM-generated Code: A Comparative Analysis21 May 2026
- 2026Surgical Repair of Insecure Code Generation in LLMs17 Apr 2026
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation10 Apr 2026
- 2026LLMs + Security = Trouble9 Feb 2026
- 2026Adaptive Hierarchical Evaluation of LLMs and SAST tools for CWE Prediction in Python4 Jan 2026