TL;DR
Before you can mathematically prove a piece of software is bug-free, you have to translate fuzzy human requirements into airtight mathematical rules—a notoriously difficult leap even for modern LLMs. SPECBRIDGE solves this by teaching models to draft an explicit "formalization blueprint" before writing any math, and introduces a clever way to essentially "run unit tests" on un-executable mathematical formulas. The result is a massive jump in generating verifiable software contracts that proof assistants can actually certify.
What Problem Does This Paper Address?
Suppose you ask an engineer to write a function: "Return only positive numbers in the list." To a human, that’s crystal clear. To a mathematical proof assistant like Lean, it’s riddled with ambiguity. What if the number 2 appears twice in the input—can the output drop the duplicate? What about order? A verification proof is only as good as the specification it checks against; if your mathematical contract forgets to enforce duplicate preservation, a buggy program will be certified as "100% correct."
Translating natural language into formal specifications (Formal Specification Synthesis) hits two major walls:
- The Representation Gap: Asking an LLM to jump straight from casual English to Lean's dependent type theory forces it to simultaneously deduce hidden edge cases, quantifier scopes, and finicky syntax in a single bound.
- The Feedback Bottleneck: How do you grade a generated math formula? Proving two formal specifications are mathematically equivalent is often harder than verifying the code itself! Because mathematical propositions aren't executable code, you can't just run unit tests on them, leaving models with sparse, unhelpful feedback when they fail.
Methods
To cross the representation gap, the authors introduce SPECBRIDGE, centered around a Natural-Language Formalization Plan (NLFP). Instead of writing Lean code immediately, the model writes a semi-structured, readable text checklist detailing exact formalization choices—like collection semantics (preserving duplicates), guard placements, and input-output relations—before decoding into Lean.
How does the model learn what belongs in a good plan without updating model weights? Through iterative prompt refinement driven by two parallel paths over 5 training rounds:
- Auto-Encoding (Reconstruction): An encoder translates a ground-truth Lean spec into an NLFP, and a decoder translates it back to Lean. Whatever structural details must survive this round-trip teach the system what makes a complete plan.
- Task-Generation (Transfer): A generator maps raw English requirements into an NLFP, sharing the exact same decoder.
To break the feedback bottleneck, SPECBRIDGE introduces a multi-layer evaluation protocol (used both as a training reflection signal to rewrite prompts and as final metrics) that approximates "unit testing" on math:
- LLM Specification Alignment: An LLM judge checks high-level semantic intent against reference specs.
- Validation Feedback (Python): An LLM translates the Lean specification into executable Python pre/post-condition checks and runs them against sampled input-output pairs from a canonical program.
- Verification Feedback (Lean): Within Lean itself, the system plugs concrete positive behaviors (e.g.,
[2,2,3]) and corrupted negative behaviors (e.g.,[2,3]) into dummy implementations, asking the Lean kernel to formally prove the spec accepts the good and rejects the bad.
Datasets
The authors use two benchmarks pairing natural-language tasks, formal Lean signatures, reference specs, and canonical Python code:
- CLEVER: Used via 5-fold cross-validation for primary training, prompt refinement, and baseline comparisons.
- VERINA (189 tasks): Used purely as a held-out evaluation dataset to test zero-shot, frozen-prompt transfer. No new benchmarks were introduced.
Key Insights and Ideas
- Reverse-engineering math teaches forward planning: When the auto-encoding path was ablated, semantic alignment plummeted by 20 percentage points. Reconstructing existing formal specs forces prompts to notice subtle structural anchors that forward generation overlooks.
- Fast Python checks and strict Lean proofs catch each other's blind spots: Translated Python checks quickly sweep broad behaviors, while Lean proofs catch subtle type/representation bugs (like invalid string indexing in Lean) that look fine in Python.
- Smarter models can write "textbooks" for smaller models: Prompts refined by
gpt-5.4can be frozen and handed todeepseek-v3.2at inference time, boosting DeepSeek’s proof validation from 69% to 78%—outperforming prompts DeepSeek refined for itself!
Key Results
On the CLEVER benchmark (using gpt-5.4), SPECBRIDGE substantially outperforms the standard Few-shot + Chain-of-Thought (CoT) baseline across all metrics:
- LLM Specification Alignment: 67% vs. 61% (+6.1 percentage points).
- Computable Validation Pass Rate (Python): 91% vs. 76% (+15.2 percentage points).
- Proof Validation Pass Rate (Lean): 87% vs. 58% (+28.4 percentage points).
It also beats unconstrained "Free-form Plan-then-Spec" (76% proof pass rate) and direct Lean feedback loops without NLFPs (80%). Furthermore, freezing the CLEVER-learned prompts and testing directly on all 189 VERINA tasks jumped Proof Validation from 83% to 94%, and Alignment from 56% to 89%.
Limitations and Future Work
- Small, stateless scope: Evaluations focus on single-function input-output contracts. Multi-function APIs, mutable state, heap ownership, concurrency, and temporal logic remain untested.
- Ambiguity isn't magic: An NLFP forces a model to commit to an interpretation, not read minds. If a human prompt genuinely doesn't imply whether list order matters, real-world systems will still need interactive clarification from the user.
- Oracle reliance & non-equivalence: Training feedback relies on having an executable canonical program, and passing concrete behavioral probes—even kernel-checked ones—is sampled evidence, not a full mathematical proof of specification equivalence. Future directions point toward better requirement clarification and tighter boundary-case feedback.
Summary updated