SpecBridge: Learning Natural-Language Formalization Plans for the Formal Specification Synthesis Task

Wenjie Zhang, Yun Lin, Zining He, Meiqi Wu, Jin Song DongNeurIPS 2026

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:

  1. 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.
  2. 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.

Figure 2: A prompt-guided motivating example. Natural-language input and an excerpt from a learned NL-to-NLFP prompt jointly guide the illustrated plan. The prompt calls for preserving collection semantics, including multiplicities/counts rather than relying on membership alone. The plan records positivity, coverage, and duplicate preservation before Lean decoding; behavioral probes then test the resulting relation. This schematic illustration is not a verbatim model trace or a proof of specification equivalence.

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.
Figure 3: SPECBRIDGE training overview. Blue arrows show the auto-encoding path from a reference specification through an NLFP to a reconstructed specification. Orange arrows show the task- generation path from natural language through an NLFP to a generated specification. Both paths share the formal decoder. Reference specifications are used only during training and evaluation.

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:

  1. LLM Specification Alignment: An LLM judge checks high-level semantic intent against reference specs.
  2. 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.
  3. 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.4 can be frozen and handed to deepseek-v3.2 at 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

Abstract

Software requirements are usually written in natural language, which is essential for human communication but insufficient as a target for machine-checked correctness. While natural-language descriptions can state intended functionality, verification requires formal specifications with explicit types, relations, quantifiers, guards, witnesses, and edge cases. To bridge this divide, we study the Formal Specification Synthesis task: given a natural-language programming requirement and fixed formal signatures, synthesize a proof-assistant specification for the intended input-output relation. This task is difficult for two primary reasons. First, a large representation gap separates informal natural language from the rigorous structures needed by a proof assistant. Second, generated formal specifications are notoriously hard to evaluate, as proving full equivalence between specifications is often too complex to serve as routine feedback. To address these intertwined challenges, we propose SpecBridge, a reconstruction-guided formalization framework. At its core, SpecBridge introduces a Natural-Language Formalization Plan (NLFP), a semi-structured, readable intermediate representation that captures key formalization choices before decoding to a target specification language. Through reconstruction-guided pattern mining, SpecBridge learns these NLFPs by reconstructing formal specifications to discover reusable patterns, ultimately transferring them to improve natural-language task generation. Furthermore, to tackle the evaluation bottleneck, we introduce a multi-layer evaluation protocol for formal-specification correctness. This protocol utilizes LLM Specification Alignment as an LLM-based judge, alongside Validation Feedback and Verification Feedback, which approximate "running" testcases on formal specifications by translating propositions into executable pre/post checks and proving testcase obligations in Lean. In our experiments, SpecBridge outperforms the few-shot + CoT baseline by 6.1, 15.2, and 28.4 percentage points on LLM Specification Alignment, Computable Validation Pass Rate, and Proof Validation Pass Rate, respectively. These results show improved specification quality under our evaluation protocol.
BibTeX
@inproceedings{zhang2026specbridge,
  author = {Wenjie Zhang and Yun Lin and Zining He and Meiqi Wu and Jin Song Dong},
  title = {{SpecBridge: Learning Natural-Language Formalization Plans for the Formal Specification Synthesis Task}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=ui1AYUwFTN},
}
Figure