AI
New Framework Automatically Converts Documentation into Formal Software Specifications
Researchers present Doc2Spec, a multi-agent system that uses grammar induction to transform natural-language API rules into precise formal specifications for verification and testing.
Creating formal specifications from natural-language documentation has long been a bottleneck in software verification. These precise, machine-readable rules are essential for catching bugs and security flaws, yet writing them by hand is tedious and error-prone. A new research framework tackles this problem by automating the conversion process.
The Problem with Manual Specifications#
Formal verification tools can provide strong guarantees about code correctness and security, but they require detailed, unambiguous specifications to work from. In practice, such specs are typically scattered across API documentation, design notes, and coding standards—all written in ordinary English. Extracting and formalizing those rules manually is costly, slow, and prone to mistakes that undermine the entire verification effort.
How Doc2Spec Works#
The new approach, called Doc2Spec, uses a multi-agent workflow guided by grammar induction. Rather than trying to translate each rule independently in one shot, the system breaks the process into staged steps:
- It fixes a domain-agnostic logical skeleton as a grammar template
- It prompts large language models to infer domain-specific predicates and sorts tailored to the problem
- It formalizes each natural-language rule within the resulting grammar
- It validates each step, turning one unreliable translation into a sequence of constrained, checkable ones
By anchoring the formalization process in an inferred grammar, the method reduces hallucinations and errors that plague direct translation.
Validation and Impact#
The framework was tested on six benchmarks spanning Solidity (a smart-contract language) and Rust, measuring how well the inferred specifications matched ground-truth formal rules. Results showed substantial improvements over baselines: 28 percentage points better precision and 37 percentage points better recall compared to systems that skip grammar induction or perform it in a single, unstaged step.
To demonstrate real-world value, researchers used the formalized rules with symbolic-execution tools to search for violations in existing code. The effort uncovered 142 previously unknown rule breaches, validating both the correctness of the inferred specs and their utility for finding bugs.

