Skip to content

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

Wenjie Zhang, Yun Lin, Zining He, Meiqi Wu, Jin Song Dong

cs.SE

Abstract

LLMs now generate large amounts of usable code, but formal verification can certify it only against a specification, and in practice the intended specification usually exists only as an informal natural-language comment. We study Formal Specification Synthesis: given a natural-language requirement and a fixed formal signature, synthesize a Lean specification of the intended input-output relation. Direct LLM translation makes formalization choices, such as relation shape, guard scope, and collection semantics, implicitly in one step, and often yields plausible but under-constrained specifications. We present SpecBridge, which introduces a learned intermediate representation, the Natural-Language Formalization Plan (NLFP), before Lean generation. A fixed NLFP grammar gives each formalization choice an explicit slot (e.g., soundness, coverage, and multiplicity obligations); what is learned are reusable formalization instructions in the prompts that write and read NLFPs. Learning these instructions lacks supervision in two ways. No plan annotations exist, so plans are supervised by reconstruction: reference specifications are encoded into NLFPs and decoded back by a shared decoder, so a plan is adequate only if the reference can be rebuilt from it. Equivalence between specifications is rarely provable, so SpecBridge approximates semantic similarity to the reference on testcases derived from a canonical program: validation feedback runs the specification as executable pre/post-condition checks, and verification feedback uses Lean proofs to check that it accepts correct outputs and rejects corrupted ones. On CLEVER, SpecBridge improves over few-shot + CoT by 6.1, 15.2, and 28.4 percentage points in LLM-judged specification alignment and in validation and verification pass rates, and its learned prompts transfer across LLM backends and to VERINA.

Create a lesson

Metadata

Comments
Accepted at NeurIPS 2026. 24 pages, 9 figures, 9 tables