TUHH Open Research
Help
  • Log In
    New user? Click here to register.Have you forgotten your password?
  • English
  • Deutsch
  • Communities & Collections
  • Publications
  • Research Data
  • People
  • Institutions
  • Projects
  • Statistics
  1. Home
  2. TUHH
  3. Publications
  4. Discrete prompt optimization using genetic algorithm for secure Python code generation
 
Options

Discrete prompt optimization using genetic algorithm for secure Python code generation

Citation Link: https://doi.org/10.15480/882.16244
Publikationstyp
Journal Article
Date Issued
2025-10-26
Sprache
English
Author(s)
Tony, Catherine  orcid-logo
Software Security E-22  
Pintor, Maura  
Kretschmann, Max  
Scandariato, Riccardo  
Software Security E-22  
TORE-DOI
10.15480/882.16244
TORE-URI
https://hdl.handle.net/11420/59052
Lizenz
https://creativecommons.org/licenses/by/4.0/
Journal
The journal of systems and software  
Volume
232
Article Number
112682
Citation
Journal of Systems and Software 232: 112682 (2026)
Publisher DOI
10.1016/j.jss.2025.112682
Scopus ID
2-s2.0-105021869941
Publisher
Elsevier
Large language models (LLMs) have become powerful tools that enable novice developers to generate production-level code. However, research has highlighted the security risks associated with such code generation, due to the high volume of generated software vulnerabilities. Recent studies have explored various techniques for automatically optimizing prompts to elicit desired responses from LLMs. Among these methods, Genetic Algorithms (GAs), which search for optimal solutions by evolving an initial population of candidates through iterative mutations, have gained attention as a lightweight and effective prompt optimization approach that does not require large datasets or access to model weights. However, their potential has not yet been examined in the context of secure code generation. In this paper, we use GA to develop a discrete prompt optimization pipeline specifically designed for secure code generation. We introduce two domain-specific prompt mutation techniques and assess how incorporating these security-focused mutations alongside general-purpose techniques, such as back translation and paraphrasing, affects the security of Python code generated by LLMs. Results demonstrate that our security-specific mutation techniques led to prompts with richer security context compared to the generic mutation techniques. Furthermore, combining these techniques with generic mutations substantially reduced the number of security weaknesses in the LLM-generated code. We also observed that prompts optimized for a particular LLM tend to perform best on that same model, highlighting the importance of model-specific prompt optimization.
Subjects
Genetic algorithms
LLMs
Prompt optimization
Secure code generation
DDC Class
004: Computer Sciences
005: Computer Programming, Programs, Data and Security
Funding(s)
Projekt DEAL  
Publication version
publishedVersion
Loading...
Thumbnail Image
Name

1-s2.0-S0164121225003516-main.pdf

Size

10.92 MB

Format

Adobe PDF

TUHH
Weiterführende Links
  • Contact
  • Send Feedback
  • Cookie settings
  • Privacy policy
  • Impress
DSpace Software

Built with DSpace-CRIS software - Extension maintained and optimized by 4Science
Design by effective webwork GmbH

  • Deutsche NationalbibliothekDeutsche Nationalbibliothek
  • ORCiD Member OrganizationORCiD Member Organization
  • DataCiteDataCite
  • Re3DataRe3Data
  • OpenDOAROpenDOAR
  • OpenAireOpenAire
  • BASE Bielefeld Academic Search EngineBASE Bielefeld Academic Search Engine
Feedback