Skip to content
Preprint

TrustedCode: Evaluating Large Language Models for Developing Trusted Code through Automated Program Verification

Oct 2026 · 0 citations · 5 references
Computer Science

TL;DR

This work presents TrustedCode, an automated framework for verifying AI-generated Python code, which uses LLMs to type-check Python code, translate it into WhyML via the Why3 framework, and verify it against formal specifications using Why3 back-end automated theorem provers.

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: \href{github.com/mtaimoorkhan/TrustedCode}{github.com/mtaimoorkhan/TrustedCode}. The video demonstration is available at: \href{youtu.be/Nr5I2g8ec-s}{youtu.be/Nr5I2g8ec-s}

View source

Similar papers

Self-Spec Verifiable Code Generation

VeriCodeBench is introduced, a benchmark for self-spec verifiable code generation, where the LLM relies solely on its own generated specification and code throughout the entire process, and CodeNova is introduced to enhance the capabilities of LLMs in self-spec verifiable code generation.

Jia-Ru Qian, Yihong Dong, Yong-Ming Li et al. · 0 citations
#software testing Book Open access Oct 2026

CoVerif: An Automated Contract Verifier for Java using Symbolic Execution

Specifying contracts as program behavior using Hoare triples is an established practice in software engineering. Compared to traditional testing approaches, formal verification of these contracts provides stronger guarantees of functional correctness. However, its practical adoption has remained limited since significa...

Aryan Kumar, Alex Toppo, Sandip Ghosal · 0 citations
Preprint Nov 2026

VeriBase: Automated Construction of Theorem Libraries for Software Verification

Software verification is typically more challenging than coding. Software developers routinely build on mature libraries and APIs, but turning successful verification solutions into reusable libraries still requires substantial expert effort. In this paper, we propose VeriBase, a framework for automatically constructin...

Zi-Hao Zhang, Ze-Nan Li, Taolue Chen et al. · 0 citations
Preprint Oct 2026

Beyond Functional Correctness: Static Code Quality Profiling of LLM-Generated Code

Large language models (LLMs) are increasingly used for code generation, yet most evaluations still focus on whether generated code passes benchmark test suites. Functional correctness alone, however, provides only a limited view of quality: benchmark tests are often incomplete, and passing them does not guarantee that...

Jue-Zhe Huang, Tarek Mahmud, Mei-Ru Che et al. · 0 citations
Book Open access Nov 2026

Securing Software in the Age of Large Language Models

Large Language Models (LLMs) offer new capabilities for software security by interpreting source code and natural-language specifications, and generating plausible code. However, their probabilistic behavior, hallucinations, limited security knowledge, and inconsistent outputs make their direct use non-trivial. This di...

Varun Gadey · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.