Compiling Successfully ≠ Translating Correctly: Semantic Pitfalls in Autoformalization and How to Address Them

    Autoformalization—translating natural language theorems into formal languages—breaks a long-standing rule of thumb in formal verification: that code which compiles and type-checks is basically correct. Studies report that nearly all generated formalizations compile, yet roughly 30% deviate from the meaning of the original statement. This article explains why a proof assistant's kernel cannot catch this gap, what kinds of semantic drift typically occur, and how to fix evaluation and pipelines: dual structural and semantic metrics, a dedicated semantic validation stage, human double-blind review, back-translation cross-checking, counterexample testing, and prompt patterns that anchor premises explicitly.

    1. A Long-Assumed Default Is Starting to Fail

    In formal verification, practitioners have long relied on a rule of thumb: if code compiles and passes the proof assistant’s type checks, it is basically “correct.”

    That rule holds up reasonably well for automated theorem proving. The target theorem is given in advance and fixed; the AI’s only job is to construct a proof, and the kernel checks each proof step. Passing means the proof succeeded.

    The rule quietly breaks down when the task shifts to autoformalization—translating a natural language theorem into a formal language. In recent work, research teams had multiple AI systems formalize the same batch of mathematical statements. Nearly every output compiled successfully, yet after manual semantic review, about 30% of the “compiling” code had drifted away from the real meaning of the original statement. That gap of nearly 30 percentage points is the core of the problem.

    2. Why Type Checking Cannot Catch “Off-Topic” Output

    To understand the gap, you first need to know what the kernel of a proof assistant actually checks.

    2.1 The Scope of the Kernel’s Responsibility

    Think of the kernel as an extremely pedantic grammar teacher:

    • It strictly checks whether the syntax of every line is legal;
    • It strictly checks whether types match and whether the proof structure is internally consistent;
    • It does not judge whether what you wrote is on topic.

    In other words, the kernel guarantees that “this statement is legal and self-consistent within this formal system,” not that “this statement expresses what you originally meant.”

    2.2 Translation Introduces Two Degrees of Freedom

    In theorem proving, the target statement is supplied externally, so the AI has exactly one degree of freedom: writing the proof. In autoformalization, the flow usually looks like this:

    1. Natural language statement
    2. ↓ AI generates a formal statement (degree of freedom 1)
    3. ↓ AI adds a placeholder proof (e.g., an empty proof such as by sorry) (degree of freedom 2)
    4. Compiles successfully

    The critical step is the first one: the target statement itself is generated by the AI. The AI can easily produce a statement with flawless syntax, perfectly matching types, and a clean compile, whose semantics are already “off by a hair, wrong by a mile” relative to the source. The placeholder proof compounds the problem—compilation checks only structural completeness, not the truth of the statement.

    2.3 An Intuitive Analogy

    It is like asking someone to translate “He didn’t come to work yesterday,” and receiving a grammatically perfect sentence that drops a key qualifier from the source—for example, “because he was sick.” A grammar checker can do nothing about this, because “is the meaning right?” is simply not part of its job description.

    Typical forms of semantic drift include:

    • Weakened quantifier strength: turning “every continuous map on a compact space satisfies property P” into “there exists a map satisfying property P”—logically, these are entirely different statements;
    • Premises silently added or dropped: if the source requires “non-empty and closed under multiplication and inversion,” the translation may keep only one of those constraints, changing the statement from “always true” to “possibly true or false,” or from a “conditional assertion” to an “overly strong assertion”;
    • Lost implicit conventions: mathematical texts often rely on contextual defaults (for instance, assuming spaces satisfy separation axioms). Omitting these conventions during formalization changes the meaning of the statement.

    3. The Numbers: How Much “Water” Is in the Compile Rate

    One research team built tool-augmented agents to perform autoformalization and compared two metrics:

    Metric Meaning Result
    Compile rate Code is accepted by the kernel ~87%
    Semantic acceptance rate Human reviewers judge it a faithful rendering of the original ~58%

    The gap of nearly 30 percentage points means that out of every ten statements that “look like they passed,” roughly three are actually mistranslated. If engineering practice filters outputs on compilation alone, these “syntactically correct but semantically off-target” statements go straight into the downstream proving and verification pipeline—where errors get amplified rather than caught.

    4. Proper Evaluation and Engineering Countermeasures

    4.1 Build a Dual-Metric Evaluation System

    Evaluation of any autoformalization system should include at least:

    • Structural metrics: compile rate, type-check pass rate;
    • Semantic metrics: equivalence judgment between the statement and the source text—an indispensable gold standard.

    Only when both are satisfied can you claim the translation succeeded. Semantic judgment can follow several human-machine combined paths:

    • Human double-blind review: domain-familiar reviewers judge independently, without being told whether the code compiled, to avoid anchoring effects;
    • AI-assisted cross-validation: have an independent model perform “back-translation” (formal code back to natural language), then compare similarity and entailment against the source as a pre-filter ahead of human review;
    • Automated refutation testing: try to construct a counterexample to the generated statement, or prove its negation—if the negation also goes through, the statement’s strength has been weakened.

    4.2 Add a “Semantic Validation” Gate to the Pipeline

    The recommended pipeline structure in practice is:

    1. Natural language statement
    2. → Formalization generation (multiple models, multiple samples)
    3. → Compilation and type checking (eliminate structural errors)
    4. → Semantic equivalence validation (eliminate off-target output) ← key new gate
    5. → Human spot checks (quality backstop)
    6. → Enter the formal proof stage

    The semantic validation gate can apply heuristic filtering by comparing consistency across multiple candidate translations: if several independent models produce mutually non-equivalent translations of the same source statement, the translation is ambiguous or high-risk and should be routed to human review first.

    4.3 Anchor Semantics in Prompts and Tool Use

    When using a large model for formalization translation, you can require it to output, alongside the formal statement:

    1. The formal statement itself;
    2. A natural language restatement of that statement;
    3. An item-by-item list of the premises in the source text and their corresponding formal terms.

    This “self-explanation” mechanism makes omitted premises easier to surface and gives reviewers comparison material for later checks.

    5. Conclusion: From “It Compiles” to “It Says the Right Thing”

    Compiling is a necessary condition for a formalization translation, not a sufficient one. The kernel guarantees legality at the language level; faithfulness at the semantic level depends on independent validation—whether human review, back-translation comparison, or counterexample testing.

    For teams building mathematical formalization systems, code-generation quality evaluation systems, or anything involving conversion from natural language to a strict formal system, the core lesson is the same: do not let structural checks substitute for semantic review. Only by measuring and optimizing “compile rate” and “semantic correctness rate” separately can you truly answer the most fundamental question—is the sentence the machine wrote actually the sentence you wanted it to write?