TypePilot: Leveraging the Scala Type System for Secure LLM-generated Code

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Sternfeld, Alexander, Kucharavy, Andrei, Dolamic, Ljiljana
Format: Preprint
Publié: 2025
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866915549661888512
author Sternfeld, Alexander
Kucharavy, Andrei
Dolamic, Ljiljana
author_facet Sternfeld, Alexander
Kucharavy, Andrei
Dolamic, Ljiljana
contents Large language Models (LLMs) have shown remarkable proficiency in code generation tasks across various programming languages. However, their outputs often contain subtle but critical vulnerabilities, posing significant risks when deployed in security-sensitive or mission-critical systems. This paper introduces TypePilot, an agentic AI framework designed to enhance the security and robustness of LLM-generated code by leveraging strongly typed and verifiable languages, using Scala as a representative example. We evaluate the effectiveness of our approach in two settings: formal verification with the Stainless framework and general-purpose secure code generation. Our experiments with leading open-source LLMs reveal that while direct code generation often fails to enforce safety constraints, just as naive prompting for more secure code, our type-focused agentic pipeline substantially mitigates input validation and injection vulnerabilities. The results demonstrate the potential of structured, type-guided LLM workflows to improve the SotA of the trustworthiness of automated code generation in high-assurance domains.
format Preprint
id arxiv_https___arxiv_org_abs_2510_11151
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle TypePilot: Leveraging the Scala Type System for Secure LLM-generated Code
Sternfeld, Alexander
Kucharavy, Andrei
Dolamic, Ljiljana
Computation and Language
Cryptography and Security
Large language Models (LLMs) have shown remarkable proficiency in code generation tasks across various programming languages. However, their outputs often contain subtle but critical vulnerabilities, posing significant risks when deployed in security-sensitive or mission-critical systems. This paper introduces TypePilot, an agentic AI framework designed to enhance the security and robustness of LLM-generated code by leveraging strongly typed and verifiable languages, using Scala as a representative example. We evaluate the effectiveness of our approach in two settings: formal verification with the Stainless framework and general-purpose secure code generation. Our experiments with leading open-source LLMs reveal that while direct code generation often fails to enforce safety constraints, just as naive prompting for more secure code, our type-focused agentic pipeline substantially mitigates input validation and injection vulnerabilities. The results demonstrate the potential of structured, type-guided LLM workflows to improve the SotA of the trustworthiness of automated code generation in high-assurance domains.
title TypePilot: Leveraging the Scala Type System for Secure LLM-generated Code
topic Computation and Language
Cryptography and Security
url https://arxiv.org/abs/2510.11151