Leveraging the Scala type system for secure LLM-generated code

Alexander Sternfeld, Ljiljana Dolamic, Andrei Kucharavy


Abstract
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 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.
Anthology ID:
2025.ommm-1.11
Volume:
Proceedings of Interdisciplinary Workshop on Observations of Misunderstood, Misguided and Malicious Use of Language Models
Month:
September
Year:
2025
Address:
Varna, Bulgaria
Editors:
Piotr Przybyła, Matthew Shardlow, Clara Colombatto, Nanna Inie
Venues:
OMMM | WS
SIG:
Publisher:
INCOMA Ltd., Shoumen, Bulgaria
Note:
Pages:
95–103
Language:
URL:
https://aclanthology.org/2025.ommm-1.11/
DOI:
Bibkey:
Cite (ACL):
Alexander Sternfeld, Ljiljana Dolamic, and Andrei Kucharavy. 2025. Leveraging the Scala type system for secure LLM-generated code. In Proceedings of Interdisciplinary Workshop on Observations of Misunderstood, Misguided and Malicious Use of Language Models, pages 95–103, Varna, Bulgaria. INCOMA Ltd., Shoumen, Bulgaria.
Cite (Informal):
Leveraging the Scala type system for secure LLM-generated code (Sternfeld et al., OMMM 2025)
Copy Citation:
PDF:
https://aclanthology.org/2025.ommm-1.11.pdf
Optionalsupplementarymaterial:
 2025.ommm-1.11.OptionalSupplementaryMaterial.zip