PromSec: Prompt Optimization for Secure Generation of Functional Source Code with Large Language Models (LLMs)
Not on the map. Why?
Abstract (arXiv)
The capability of generating high-quality source code using large language models (LLMs) reduces software development time and costs. However, they often introduce security vulnerabilities due to training on insecure open-source data. This highlights the need for ensuring secure and functional code generation. This paper introduces PromSec, an algorithm for prom optimization for secure and functioning code generation using LLMs. In PromSec, we combine 1) code vulnerability clearing using a generative adversarial graph neural network, dubbed as gGAN, to fix and reduce security vulnerabilities in generated codes and 2) code generation using an LLM into an interactive loop, such that the outcome of the gGAN drives the LLM with enhanced prompts to generate secure codes while preserving their functionality. Introducing a new contrastive learning approach in gGAN, we formulate code-clearing and generation as a dual-objective optimization problem, enabling PromSec to notably reduce the number of LLM inferences. PromSec offers a cost-effective and practical solution for generating secure, functional code. Extensive experiments conducted on Python and Java code datasets confirm that PromSec effectively enhances code security while upholding its intended functionality. Our experiments show that while a state-of-the-art approach fails to address all code vulnerabilities, PromSec effectively resolves them. Moreover, PromSec achieves more than an order-of-magnitude reduction in operation time, number of LLM queries, and security analysis costs. Furthermore, prompts optimized with PromSec for a certain LLM are transferable to other LLMs across programming languages and generalizable to unseen vulnerabilities in training. This study is a step in enhancing the trustworthiness of LLMs for secure and functional code generation, supporting their integration into real-world software development.
Key facts. Cited by 17 papers in the map (data through 7 Oct 2026). Builds on 32 of its 75 references that are in the map. First posted on arXiv 19 Sep 2024.
Builds on
32 of 75 references.
References · 32
- 2017Attention Is All You Needcited by 59,932
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2020A Simple Framework for Contrastive Learning of Visual Representationscited by 11,979
- 2016Semi-Supervised Classification with Graph Convolutional Networkscited by 11,282
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2019A Comprehensive Survey on Graph Neural Networkscited by 2,906
- 2021Pre-train, Prompt, and Predict: A Systematic Survey of Prompting Methods in Natural Language Processingcited by 2,222
- 2016Variational Graph Auto-Encoderscited by 1,373
- 2018Deep Graph Infomaxcited by 1,101
- 2022Large Language Models Are Human-Level Prompt Engineerscited by 1,020
- 2021GPT Understands, Toocited by 715
20 more
- 2023Automatic Prompt Optimization with "Gradient Descent" and Beam Searchcited by 628
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
- 2021Learning How to Ask: Querying LMs with Mixtures of Soft Promptscited by 376
- 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 266
- 2017Learning to Represent Programs with Graphscited by 219
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
- 2018SequenceR: Sequence-to-Sequence Learning for End-to-End Program Repaircited by 144
- 2017GraphGAN: Graph Representation Learning with Generative Adversarial Netscited by 121
- 2022Productivity Assessment of Neural Code Completioncited by 97
- 2023Guiding Large Language Models via Directional Stimulus Promptingcited by 94
- 2020Detecting Code Clones with Graph Neural Networkand Flow-Augmented Abstract Syntax Treecited by 68
- 2020Deep Learning for Source Code Modeling and Generation: Models, Applications and Challengescited by 55
- 2023A New Era in Software Security: Towards Self-Healing Software via Large Language Models and Formal Verificationcited by 42
- 2019GCN-GAN: A Non-linear Temporal Link Prediction Model for Weighted Dynamic Networkscited by 40
- 2021A large-scale study on research code quality and executioncited by 22
- 2022AixBench: A Code Generation Benchmark Datasetcited by 22
- 2024LLM-Powered Code Vulnerability Repair with Reinforcement Learning and Semantic Rewardcited by 16
- 2021Toward Code Generation: A Survey and Lessons from Semantic Parsingcited by 8
- 2018SMT-Based Refutation of Spurious Bug Reports in the Clang Static Analyzercited by 5
Built on by
Citing papers per year: 2024: 1; 2025: 7; 2026: 9.
17 papers.
Sort:
By area:
- 2025PurpCode: Reasoning for Safer Code Generationcited by 17
- 2025SecRepoBench: Benchmarking Code Agents for Secure Code Completion in Real-World Repositoriescited by 14
- 2025Training Language Models to Generate Quality Code with Program Analysis Feedbackcited by 11
- 2025Rethinking the Evaluation of Secure Code Generationcited by 10
- 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
- 2024Helping LLMs Improve Code Generation Using Feedback from Testing and Static Analysiscited by 6
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilitiescited by 4
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistantscited by 3
- 2025Prompt engineering and framework: implementation to increase code reliability based guideline for LLMscited by 1
- 2026Enhancing Reliability in LLM-Based Secure Code Generationcited by 1
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanismscited by 0
- 2026A Quasi-Experimental Developer Study of Security Training in LLM-Assisted Web Application Developmentcited by 0
5 more
- 2026Willing but Unable: Separating Refusal from Capability in Code LLMs via Abliterationcited by 0
- 2026Activating Latent Security Knowledge through LLM-Guided Risk Analysis for Secure Code Generationcited by 0
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
- 2026From Adoption to Deployment: A Qualitative Study on AI Integration in Software Development Practicecited by 0
- 2026The Illusion of Secure LLM Code: Closing the Security Gap via Iterative Repromptingcited by 0
- 2026The Illusion of Secure LLM Code: Closing the Security Gap via Iterative Reprompting26 Jul 2026
- 2026From Adoption to Deployment: A Qualitative Study on AI Integration in Software Development Practice18 Jul 2026
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward23 Jun 2026
- 2026Activating Latent Security Knowledge through LLM-Guided Risk Analysis for Secure Code Generation15 Jun 2026
- 2026Willing but Unable: Separating Refusal from Capability in Code LLMs via Abliteration3 Jun 2026
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistants29 May 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
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanisms11 Mar 2026
- 2025RESCUE: Retrieval Augmented Secure Code Generation21 Oct 2025
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilities30 Sep 2025
- 2025PurpCode: Reasoning for Safer Code Generation25 Jul 2025
5 more
- 2025Training Language Models to Generate Quality Code with Program Analysis Feedback28 May 2025
- 2025SecRepoBench: Benchmarking Code Agents for Secure Code Completion in Real-World Repositories29 Apr 2025
- 2025Prompt engineering and framework: implementation to increase code reliability based guideline for LLMs19 Mar 2025
- 2025Rethinking the Evaluation of Secure Code Generation18 Mar 2025
- 2024Helping LLMs Improve Code Generation Using Feedback from Testing and Static Analysis19 Dec 2024
- 2025SecRepoBench: Benchmarking Code Agents for Secure Code Completion in Real-World Repositoriescited by 14
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilitiescited by 4
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistantscited by 3
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward23 Jun 2026
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistants29 May 2026
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilities30 Sep 2025
- 2025SecRepoBench: Benchmarking Code Agents for Secure Code Completion in Real-World Repositories29 Apr 2025
- 2025PurpCode: Reasoning for Safer Code Generationcited by 17
- 2025PurpCode: Reasoning for Safer Code Generation25 Jul 2025
- 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
- 2025RESCUE: Retrieval Augmented Secure Code Generation21 Oct 2025
- 2025Training Language Models to Generate Quality Code with Program Analysis Feedbackcited by 11
- 2025Rethinking the Evaluation of Secure Code Generationcited by 10
- 2024Helping LLMs Improve Code Generation Using Feedback from Testing and Static Analysiscited by 6
- 2025Prompt engineering and framework: implementation to increase code reliability based guideline for LLMscited by 1
- 2026Enhancing Reliability in LLM-Based Secure Code Generationcited by 1
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanismscited by 0
- 2026A Quasi-Experimental Developer Study of Security Training in LLM-Assisted Web Application Developmentcited by 0
- 2026Willing but Unable: Separating Refusal from Capability in Code LLMs via Abliterationcited by 0
- 2026Activating Latent Security Knowledge through LLM-Guided Risk Analysis for Secure Code Generationcited by 0
- 2026From Adoption to Deployment: A Qualitative Study on AI Integration in Software Development Practicecited by 0
- 2026The Illusion of Secure LLM Code: Closing the Security Gap via Iterative Repromptingcited by 0
- 2026The Illusion of Secure LLM Code: Closing the Security Gap via Iterative Reprompting26 Jul 2026
- 2026From Adoption to Deployment: A Qualitative Study on AI Integration in Software Development Practice18 Jul 2026
- 2026Activating Latent Security Knowledge through LLM-Guided Risk Analysis for Secure Code Generation15 Jun 2026
- 2026Willing but Unable: Separating Refusal from Capability in Code LLMs via Abliteration3 Jun 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
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanisms11 Mar 2026
- 2025Training Language Models to Generate Quality Code with Program Analysis Feedback28 May 2025
- 2025Prompt engineering and framework: implementation to increase code reliability based guideline for LLMs19 Mar 2025
- 2025Rethinking the Evaluation of Secure Code Generation18 Mar 2025
- 2024Helping LLMs Improve Code Generation Using Feedback from Testing and Static Analysis19 Dec 2024