TrustedCode: Evaluating Large Language Models for Developing Trusted Code through Automated Program Verification
Abstract
Recent reports, such as "Who is using AI to code?", indicate that approximately 30\% of Python code contributions to GitHub are AI-generated. Given the inherent unreliability of this code, formal verification emerges as a promising approach to establish trust in software correctness. Although leveraging large language models (LLMs) for formal verification has garnered increasing attention, practical adoption remains limited due to the challenges in writing formal specifications and verifying program correctness against them. Existing tools predominantly support verification for languages such as Java and C, with minimal support for Python. We present TrustedCode, an automated framework for verifying AI-generated Python code. TrustedCode uses LLMs to (i) type-check Python code, (ii) translate it into WhyML via the Why3 framework, and (iii) verify it against formal specifications using Why3 back-end automated theorem provers. Our method integrates chain-of-thought prompting through LangGraph to identify and address LLM limitations in specification generation and proving the specified programs. To evaluate TrustedCode, we conducted experiments on ten Python programs of varying complexity. Our analysis reveals that 50\% of the observed errors stem from domain knowledge gaps, 30\% from syntactic inaccuracies, and the remaining 20\% from semantic and type-related issues. These findings underscore the importance of targeted improvements in LLM-guided formal verification workflows for Python. TrustedCode is an open source tool available at: github.com/mtaimoorkhan/TrustedCodegithub.com/mtaimoorkhan/TrustedCode. The video demonstration is available at: youtu.be/Nr5I2g8ec-syoutu.be/Nr5I2g8ec-s
Create a lesson
Metadata
- Categories
- cs.SE, cs.LO, cs.PL
Related papers
Beyond Benchmarks: Evaluating Large Language Models and Agentic Patterns for Static Code Analysis Warning Classification
Shared title terminologycs.SELakmal Deshapriya, Sherlock A. Licorish, Brendon J. Woodford et al.
From Industrial Product Documentation to Automated Digital Product Passport Generation: An Experimental Study of Large Language Models
Shared title terminologycs.SEMarco Buecheler, Grant Richards, Nathan Hartman
Scientific Coding with Large Language Models: Evidence from Finite Element Analysis
Shared title terminologycs.SEErfan Hamdi, Joel Shor, Emma Lejeune
Large Language Models for Quantum Code Translation: An Exploratory Study
Shared title terminologycs.SEXiyuan Li, Yuechen Li, Jianjun Zhao
Hallucinations of Large Language Models in Cross-Language Code Translation: Phenomena and Mitigation
Shared title terminologycs.SEYali Du, Yunji Zhang, Ming Li
When Coding Agents Outpace Review: Evaluating PRD-Driven Development in Mature Enterprise Repositories
Shared title terminologycs.SETianqi Liu, Yandong Guan, Songze Li et al.