mlsanityData to 7 Oct 2026

PromSec: Prompt Optimization for Secure Generation of Functional Source Code with Large Language Models (LLMs)

arXiv 2409.12699 ↗First posted 19 Sep 2024cs.SE cs.LGcited by 17

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

  1. 2017Attention Is All You Needcited by 59,932
  2. 2020Language Models are Few-Shot Learnerscited by 32,199
  3. 2020A Simple Framework for Contrastive Learning of Visual Representationscited by 11,979
  4. 2016Semi-Supervised Classification with Graph Convolutional Networkscited by 11,282
  5. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  6. 2021Program Synthesis with Large Language Modelscited by 3,509
  7. 2019A Comprehensive Survey on Graph Neural Networkscited by 2,906
  8. 2021Pre-train, Prompt, and Predict: A Systematic Survey of Prompting Methods in Natural Language Processingcited by 2,222
  9. 2016Variational Graph Auto-Encoderscited by 1,373
  10. 2018Deep Graph Infomaxcited by 1,101
  11. 2022Large Language Models Are Human-Level Prompt Engineerscited by 1,020
  12. 2021GPT Understands, Toocited by 715
20 more
  1. 2023Automatic Prompt Optimization with "Gradient Descent" and Beam Searchcited by 628
  2. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
  3. 2021Learning How to Ask: Querying LMs with Mixtures of Soft Promptscited by 376
  4. 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 266
  5. 2017Learning to Represent Programs with Graphscited by 219
  6. 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
  7. 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
  8. 2018SequenceR: Sequence-to-Sequence Learning for End-to-End Program Repaircited by 144
  9. 2017GraphGAN: Graph Representation Learning with Generative Adversarial Netscited by 121
  10. 2022Productivity Assessment of Neural Code Completioncited by 97
  11. 2023Guiding Large Language Models via Directional Stimulus Promptingcited by 94
  12. 2020Detecting Code Clones with Graph Neural Networkand Flow-Augmented Abstract Syntax Treecited by 68
  13. 2020Deep Learning for Source Code Modeling and Generation: Models, Applications and Challengescited by 55
  14. 2023A New Era in Software Security: Towards Self-Healing Software via Large Language Models and Formal Verificationcited by 42
  15. 2019GCN-GAN: A Non-linear Temporal Link Prediction Model for Weighted Dynamic Networkscited by 40
  16. 2021A large-scale study on research code quality and executioncited by 22
  17. 2022AixBench: A Code Generation Benchmark Datasetcited by 22
  18. 2024LLM-Powered Code Vulnerability Repair with Reinforcement Learning and Semantic Rewardcited by 16
  19. 2021Toward Code Generation: A Survey and Lessons from Semantic Parsingcited by 8
  20. 2018SMT-Based Refutation of Spurious Bug Reports in the Clang Static Analyzercited by 5

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 1; 2025: 7; 2026: 9.

17 papers.

Sort:

By area:

  1. 2025PurpCode: Reasoning for Safer Code Generationcited by 17
  2. 2025SecRepoBench: Benchmarking Code Agents for Secure Code Completion in Real-World Repositoriescited by 14
  3. 2025Training Language Models to Generate Quality Code with Program Analysis Feedbackcited by 11
  4. 2025Rethinking the Evaluation of Secure Code Generationcited by 10
  5. 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
  6. 2024Helping LLMs Improve Code Generation Using Feedback from Testing and Static Analysiscited by 6
  7. 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilitiescited by 4
  8. 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistantscited by 3
  9. 2025Prompt engineering and framework: implementation to increase code reliability based guideline for LLMscited by 1
  10. 2026Enhancing Reliability in LLM-Based Secure Code Generationcited by 1
  11. 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanismscited by 0
  12. 2026A Quasi-Experimental Developer Study of Security Training in LLM-Assisted Web Application Developmentcited by 0
5 more
  1. 2026Willing but Unable: Separating Refusal from Capability in Code LLMs via Abliterationcited by 0
  2. 2026Activating Latent Security Knowledge through LLM-Guided Risk Analysis for Secure Code Generationcited by 0
  3. 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
  4. 2026From Adoption to Deployment: A Qualitative Study on AI Integration in Software Development Practicecited by 0
  5. 2026The Illusion of Secure LLM Code: Closing the Security Gap via Iterative Repromptingcited by 0