Autoformalization: Compiling Does Not Mean Semantic Correctness
AI-generated formal statements can pass type checking while misrepresenting their natural-language sources. This article explains why compilation is insufficient for autoformalization, identifies common semantic errors, and outlines separate validation gates and evaluation metrics for faithful statements and valid proofs.
At the intersection of software and mathematics, an increasingly common task is to translate natural-language definitions, propositions, and specifications into machine-checkable formal statements.
Success is often measured by whether the output passes type checking or compiles. That is a reasonable criterion when the target proposition is already fixed and only its proof remains to be constructed. But when a model also generates the proposition itself, compiler acceptance is nowhere near enough. A grammar checker can reject malformed sentences without noticing that an essay answers the wrong question.
Automated Proving and Autoformalization Are Different Tasks
Formal verification toolchains typically include a strict kernel that checks whether syntax, types, and dependencies are valid. Thinking of it as an exceptionally rigorous grammar checker is useful.
In automated theorem proving, the proposition is usually given in advance. The system’s task is to construct a proof term. Kernel acceptance generally means that the proposition has been proved within the chosen logical framework.
Autoformalization works differently. Its input is natural language—from textbooks, papers, or requirements documents—and its output is a formal statement. The proof is often deferred using a placeholder.
A model can therefore produce well-typed, compilable code whose quantifier scope, topological assumptions, algebraic structures, or boundary conditions differ from the source. Compilation success rates consequently overestimate how much of the output is actually usable.
Public evaluations have reported this pattern: tool-augmented agents can achieve high compilation success rates, yet acceptance drops substantially when outputs are reviewed for semantic fidelity. The gap can approach 30 percentage points. In practical terms, roughly three out of every ten outputs with a green build may fail to express the original statement.
Where Semantic Drift Comes From
Semantic errors are rarely random nonsense. More often, they are structural mistakes in statements that look plausible.
Quantifiers and Scope
Natural language often leaves universal quantifiers, existential quantifiers, and the nesting of conditions implicit.
Consider: “Every continuous map from a compact space to a Hausdorff space is a closed map.” Omitting compactness, the Hausdorff condition, or continuity can leave the output well-typed while changing the proposition. Replacing “for all spaces” with “there exists a space” likewise produces a different claim.
Definition Substitution and Unwarranted Specialization
Suppose the source says that a nonempty set of real square matrices closed under multiplication and inversion must contain the identity matrix.
A model might recast the statement using a general group or ring, or silently introduce conditions such as commutativity or finite dimensionality that the source did not state. The compiler does not compare the output with the original assignment; it checks whether the current file is internally consistent.
Omitted Constraints
A phrase such as “did not come to work” may carry an explicit or contextual qualification such as “because of illness.” Dropping the reason still leaves a valid proposition, but not an equivalent one.
The same issue occurs in mathematical texts and specifications. Qualifiers involving closure, connectedness, measurability, or “almost everywhere” can disappear without preventing compilation.
Proof Placeholders That Hide Problems
Using a placeholder such as sorry or an equivalent deferred-proof mechanism can allow a declaration to pass checking before its proof exists. A pipeline may then report success prematurely at the statement-generation stage.
If the quality gate checks only build success, semantic errors can enter downstream proof search, waste computation, and contaminate datasets.
Why Compilation Is Not a Correctness Guarantee
The kernel checks whether terms are well-formed under the declared constants and types. It does not establish that a declaration means the same thing as a particular natural-language passage. Nor does it ensure that the most appropriate library definition has been selected.
A mathematical concept may have several library encodings: point-set topology and filters, sequences and nets, or matrix groups and general linear groups. An unsuitable encoding can still type-check.
Autoformalization therefore needs at least two validation layers:
- Syntax and type validity: Can the statement pass the formal checker?
- Semantic alignment: Does it faithfully express the source statement?
The first layer is inexpensive and readily automated. The second requires source-aware human review or tightly constrained evaluation. It is more costly, but it cannot be skipped.
How to Validate Semantic Alignment
Running the compiler again is not enough. In practice, teams can combine the following methods without tying the process to a particular proof assistant.
Use a Source-to-Statement Checklist
Break the source into atomic components: the domain of discourse, quantifiers, assumptions, conclusions, and exceptions.
Check the generated statement against every component. A missing requirement is a failure, even if the build succeeds.
Back-Translate and Review Differences
Translate the formal statement back into controlled natural language, then compare it structurally with the source. Focus on quantifiers, predicates, and constants.
A fluent back-translation is not sufficient evidence of correctness. The key question is whether any constraints were added, removed, or changed.
Check Library Alignment
Require the model to reference existing standard-library definitions explicitly and explain why weaker or stronger variants were not selected.
Do not allow unexplained additional axioms.
Use Adversarial Examples
Prepare paired examples in which removing a single qualifier turns a valid proposition into a false one. These cases directly test overgeneralization and unjustified restriction.
Stratify Human Review
Sample compilable outputs by difficulty and review their semantic fidelity. Report the joint rate of compilation success and semantic acceptance, as well as the gap between the two.
If that gap persists, compilation success alone should not serve as a release criterion.
A pipeline should separate statement validation from proof validation:
Input: Natural-language proposition NOutput: Formal statement S, optional proof PGate 1 — Syntax and types: Build(S) succeedsGate 2 — Semantic alignment: Align(N, S) passes // Checklist/back-translation/reviewGate 3 — Proof validity: Check P only when a complete proof is requiredRelease metric: Pr(Gate 1 ∧ Gate 2), not Pr(Gate 1)
Proof placeholders may support a smoke test at Gate 1. They provide no evidence for passing Gate 2.
Implications for Engineering and Evaluation
Teams using large language models to translate requirements into formal specifications, test oracles, or safety properties should treat compilation as necessary but insufficient.
Dataset annotations should record error categories—such as quantifier errors, omitted assumptions, and definition mismatches—rather than only binary correctness labels.
Leaderboards that report build success alone can reward models for generating weaker claims or adding stronger assumptions simply because those outputs are easier to type-check.
For cloud-based coding agents and documentation assistants, the quality view should bring together source corpora in object storage, failure samples in logging services, and monitoring signals such as semantic rejection rates.
A containerized validation pipeline can make kernel checking the fast path and route semantic review through a slower asynchronous queue. Fast-path success should not be presented externally as a guarantee of correctness.
Automation should also be described realistically. Semantic alignment in open-domain mathematics still depends heavily on experts. Models can reduce the cost of producing a first draft, but they cannot independently certify that a generated statement is the original theorem.
External reporting should include compilation success, semantic acceptance, and the gap between them. Otherwise, readers may mistake the grammar checker’s approval for confirmation that the content is correct.
Conclusion
Formal kernels are good at rejecting invalid formal code. They are not designed to decide whether that code describes the object or claim you intended.
Autoformalization delegates the choice of statement to a model, creating a systematic gap between successful compilation and faithful translation. Semantic validation gates, error categories, and joint evaluation metrics are needed to move from output that merely passes a checker to output that can be trusted.
For developers, the most useful change is not a different syntax checker. It is recognizing that even a very high compilation success rate cannot replace a component-by-component comparison with the original meaning.
