A test tells you your code works on the inputs you thought of. A proof tells you it works on every input there is. Almost nobody reaches for the second one, because the languages that can express a proof — Lean 4, Rocq, Dafny, F* — are not the languages anyone ships production code in. The logic that needs checking is in Python.
An agent can translate that Python into Lean for you. The question is whether you trust the translation. What you need is a fixed, auditable tool: same input, same output, every time. You state the correctness theorem, an agent fills in the proof, and Lean checks it. The agent can still guess wrong; what it cannot do is slip a wrong proof past the checker.
PastaLean (Py + AST + Lean) is that tool. You write ordinary Python. A fixed, deterministic translator turns it into Lean 4. Lean checks it, and if you have said what the code is supposed to do, Lean proves it.
The results
Here is what it does on three benchmarks of real Python:
| Dataset | Problems | Elaborated | Test cases | Passed |
|---|---|---|---|---|
| HumanEval⁺ | 164 | 151 (92.1%) | 7,007 | 7,007 (100%) |
| LeetCode | 2,589 | 2,391 (92.4%) | 215,126 | 208,736 (97.0%) |
| LiveCodeBench | 476 | 469 (98.5%) | 10,213 | 10,213 (100%) |
A program counts as elaborated when the Lean it produced type-checks, and a solution counts as passed only when the translated program gives CPython's answer on every one of that problem's test cases.
Why not ask a model to write the Lean?
This is the obvious shortcut, and rejecting it is the most important decision in our project.
It is not reproducible. Run a model twice and you get two translations. Auditing a non-deterministic translator audits one sample of it.
It defeats the purpose. A model translating Python to Lean may quietly fix the bug: clean up an off-by-one, pick the sensible branch, write the code you obviously meant. Desirable in an assistant, fatal in a verifier. The proof closes, you ship, and the bug is still in the Python that runs.
It measures poorly. We ran Claude Opus 4.8 on HumanEval⁺ and LiveCodeBench through the same harness PastaLean is scored with, five independent samples per problem.
| HumanEval⁺ | LiveCodeBench | |
|---|---|---|
| LLM, pass@1 — one sample works | 75.4% | 52.5% |
| LLM, pass@5 — at least one of five works | 87.2% | 74.9% |
| LLM, pass⁵ — all five work | 62.8% | 31.4% |
| PastaLean, generated Lean compiles | 92.1% | 98.5% |
| PastaLean, test cases matching CPython | 100% | 100% |
The number to look at is the distance between pass@5 and pass⁵. On LiveCodeBench the model finds a working translation within five tries three-quarters of the time, and produces five that all work less than a third of the time. A deterministic transpiler has pass⁵ equal to pass@1 by construction, because there is only ever one output. A component that is right on some runs and wrong on others can be useful, but it cannot sit in the trusted path of anything that acts on its output, however strong its average.
How it works
Transpilation runs in four stages:
- Parse. Python's own
astmodule reads the code, so there is no second grammar to keep in sync with CPython. - Annotate. Lean needs a type for every variable; Python supplies almost none. Our type inference engine, TypeInfer, works them out and changes nothing else.
- Generate. Each kind of Python construct has one Lean function that translates it, and those functions can only emit well-formed Lean. The pieces are assembled with Lean metaprogramming, so every fragment carries its type.
- Elaborate. Lean's own compiler checks the output. The Lean elaborator is the oracle, which is a trustworthy kernel: we are not comparing against hand-written golden files, we are asking a compiler whether the translation makes sense, for every program.
Here is HumanEval 85 — add the even elements at odd indices — with its specification written in the Python:
Requires, Ensures and Invariant are thin wrappers around assert, so the file still runs under CPython exactly as before. The translator lifts them out and turns them into the statement of a theorem: assuming the list is non-empty, running add on it gives back an even number. Lean then checks the proof.
Nothing about this is a test. There is no list of inputs. The statement covers every list of integers that exists.
Can you trust it?
There are two things to trust: Lean and the translation. Lean is the easy part. Every proof is checked by its small kernel, the same one the whole of Mathlib relies on, so an agent can guess wrong but can never get a wrong proof accepted. That leaves the translation: a proof about the Lean is a proof about your Python because the translation keeps its meaning.
PastaLean targets the part of Python that logic is actually written in: values, control flow, functions, classes, exceptions, and libraries such as math, numpy and pandas. Coverage means more than “it parses”. Python and Lean disagree in places where neither raises an error: 7 // -2 is -4 in Python and -3 in Lean, and left alone [1,2] + [3,4] would quietly become [4,6] instead of [1,2,3,4]. PastaLean reproduces Python's behaviour on every operator, builtin and container method, each backed by tests against CPython. Each of these is a deliberate decision about how Python's meaning maps onto Lean.
A formal semantics of Python written in Lean does not exist yet, so the strongest evidence is empirical — and it is strong. Pooled over all 3,229 programs and 232,346 test cases, 93.2% of programs elaborate and 97.2% of test cases agree with CPython. That is the standard a compiler is held to: checked against the reference implementation, on every program we have.
The 13 HumanEval programs that do not elaborate are genuine type ambiguities, such as a function that returns a list of strings for most inputs and an integer for others. Add a single type hint at the ambiguous spot and all 13 compile: 164 of 164. In other words, 92% of these need nothing from you, and the rest need one word. This shows that PastaLean doesn't guess at ambiguous code: it flags it, and one word from you resolves it.
The type inference engine holds up on its own too. On the TypeEvalPy benchmark, TypeInfer is the best static tool on the leaderboard at 72.7%, ahead of HeaderGen at 65.7%. On TypyBench, which strips the annotations from 50 real projects, it scores 0.284 against pyrefly's 0.243, and finishes in 135 seconds against pyrefly's 228.
What this changes
The division of labour falls out of the design. The model writes the Python. You state the specification. A fixed translator does the translation. An agent searches for the proof, and Lean decides. Each party does the thing it is reliable at, and the model is never in the trusted path for meaning. This is neuroformal verification in miniature: neural components where creativity is needed, formal ones where trust is needed. We expect the pattern to carry beyond Python and Lean to any setting where an autonomous system's output has to be trusted rather than sampled.
The contract is the real interface. It is the one artifact a human has to read and agree with, and the review question is small and concrete: does this sentence say what I wanted? If the code does not meet the specification, Lean refuses the proof. If the specification says the wrong thing, Lean will prove the wrong thing just as happily — which is why the contract is the artifact a human must read.
PastaLean ships an MCP server, so a model can drive the whole loop itself. One rule makes that loop worth running: the checker's verdict is the only verdict. More work is ongoing filling the remaining object-model gaps, property based testing and stronger proof automation — the tactic script that closes each proof is still the step a human writes.
PastaLean is open source at github.com/siddhartha-gadgil/PastaLean. Paper: PastaLean.