Safe Autoformalization: Sufficiency and Necessity with Entailment Graphs

Summary (Overview)

  • Core contribution: The paper introduces Entailment Graphs (EGs)—a neurosymbolic framework for safe autoformalization that certifies one-sided logical adequacy of LLM-generated candidate formulas. A formula that is sufficient for the intent is safe to enforce; one that is necessary is safe to rely on.

  • Key mechanism: Candidate formulas are ordered by logical entailment in a DAG built by a solver. Two graph searches return the sufficient frontier (weakest candidates entailing the statement) and the necessary frontier (strongest candidates entailed by the statement), which bracket the statement's meaning.

  • Ambiguity residue: The gap between frontiers yields a single formula—the ambiguity residue—that holds exactly of situations the candidates certify neither as satisfying nor violating the statement. The statement is ambiguous precisely when this residue is satisfiable.

  • Theoretical guarantees: A sound entailment oracle (LLM) makes the selection safe regardless of pool quality (Theorem 23); completeness is needed only for tightness (Theorem 24). All proofs are machine-checked in Lean 4 over an arbitrary Boolean algebra.

  • Empirical results: On AWS cloud safety properties, EG selection is safe in all 20 expert-adjudicated cases (vs. 25% unsafe for majority vote, 10% for Universal Self-Consistency). An ablation removing the graph but keeping the same oracle is unsafe in 25% of cases and rejects all candidates in another 30%.


Introduction and Theoretical Foundation

Background and Motivation

Autoformalization translates natural-language (NL) statements into formal representations (e.g., SMT-LIB formulas). With LLMs, this has become practical for domains including mathematics, temporal-logic specifications, program contracts, and security policies. However, LLM-based autoformalization carries no formal guarantees—the same statement can be formalized into multiple inequivalent formulas, and natural language is inherently ambiguous.

The paper identifies a crucial insight: in verification pipelines, the role of a formula determines what "correct" means:

  • Enforced formulas (guarantees): must be sufficient for the intent—every artifact admitted must be one the intent admits.
  • Relied-upon formulas (assumptions): must be necessary—claiming no more than the intent guarantees.

Neither role requires equivalence; each requires one direction of entailment. This mirrors the weakest-precondition/strongest-postcondition duality in program verification (Dijkstra 1975).

Theoretical Foundation: Adjoints in a Boolean Algebra

Formulas modulo equivalence, ordered by entailment, form a Boolean (hence Heyting) algebra. The two key operations are adjoints:

  • Residual (right adjoint to conjunction): Given u⊨vu \models v, the residual of vv w.r.t. uu is the weakest formula ρ\rho such that v∧ρ  ⟺  uv \wedge \rho \iff u. Classically: ρ=v⇒u\rho = v \Rightarrow u.
  • Co-residual (left adjoint to disjunction): Given u⊨vu \models v, the co-residual is the strongest formula δ\delta such that u∨δ  ⟺  vu \vee \delta \iff v. Classically: δ=v∧¬u\delta = v \wedge \neg u.

The key decompositions are:

u  ⟺  v∧(v⇒u)(Lemma 3: Residual Decomposition)u \iff v \wedge (v \Rightarrow u) \quad \text{(Lemma 3: Residual Decomposition)} v  ⟺  u∨(v∧¬u)(Lemma 5: Co-residual Decomposition)v \iff u \vee (v \wedge \neg u) \quad \text{(Lemma 5: Co-residual Decomposition)}

Lemma 6 (Absolute adjoints suffice): Relativizing adjoints to a context leaves checks unchanged—one EG serves every context.


Methodology

Entailment Graph Construction

Definition 1 (Logical Entailment Graph): A DAG whose vertices are equivalence classes of candidate formulas (under logical equivalence) and whose edges represent strict entailment: edge (u,v)(u,v) exists when u⊨vu \models v and v⊭uv \not\models u. The graph is transitively closed.

The graph is always completed with two synthetic vertices:

  • ⊥\bot (False): the unique strongest vertex (universal root)
  • ⊤\top (True): the unique weakest vertex (universal sink)

Frontier Searches

Sufficient-Frontier Search (downward, Figure 3): Starting from {⊥}\{\bot\}, weakens across edges while the co-residual check (v∧¬u)∧ctx⊨s(v \wedge \neg u) \wedge ctx \models s passes. Returns the weakest candidates entailing ss in context.

Necessary-Frontier Search (upward, Figure 4): Starting from {⊤}\{\top\}, strengthens across edges while the residual check s∧ctx⊨(v⇒u)s \wedge ctx \models (v \Rightarrow u) passes. Returns the strongest candidates entailed by s∧ctxs \wedge ctx.

Key theorems:

  • Theorem 7: If u∧ctx⊨su \wedge ctx \models s, then v∧ctx⊨sv \wedge ctx \models s iff (v∧¬u)∧ctx⊨s(v \wedge \neg u) \wedge ctx \models s.
  • Theorem 8: If s∧ctx⊨vs \wedge ctx \models v, then s∧ctx⊨us \wedge ctx \models u iff s∧ctx⊨(v⇒u)s \wedge ctx \models (v \Rightarrow u).
  • Theorem 9/10: Both searches are correct—returning weakest sufficient / strongest necessary candidates.
  • Lemma 11 (Frontier Completeness): Frontiers are exactly the extremal elements of the sets {w∣w∧ctx⊨s}\{w \mid w \wedge ctx \models s\} and {w∣s∧ctx⊨w}\{w \mid s \wedge ctx \models w\}.

Ambiguity Residue

Definition 15: Amb(s;EG,ctx)=φ↑∧¬φ↓∧ctx\text{Amb}(s; EG, ctx) = \varphi_{\uparrow} \wedge \neg\varphi_{\downarrow} \wedge ctx, where φ↓=⋁v∈F↓v\varphi_{\downarrow} = \bigvee_{v \in F_{\downarrow}} v and φ↑=⋀u∈F↑u\varphi_{\uparrow} = \bigwedge_{u \in F_{\uparrow}} u.

Theorem 17 (Disambiguation Criterion): The residue is unsatisfiable iff φ↑∧ctx⊢φ↓\varphi_{\uparrow} \wedge ctx \vdash \varphi_{\downarrow}, which holds iff φ↓∧ctx  ⟺  s∧ctx  ⟺  φ↑∧ctx\varphi_{\downarrow} \wedge ctx \iff s \wedge ctx \iff \varphi_{\uparrow} \wedge ctx.

Proposition 20 (Monotonicity): Adding candidates or strengthening the context can only shrink the residue.

Neurosymbolic Realization

The implementation splits responsibilities:

  • SMT solver (cvc5): Builds the EG, computes residuals/co-residuals, checks candidate entailments.
  • LLM oracle: Answers only local edge checks of two shapes:
(v∧¬u)∧ctx~⊨s~,s~∧ctx~⊨(v⇒u)(v \wedge \neg u) \wedge \widetilde{ctx} \models \widetilde{s}, \quad \widetilde{s} \wedge \widetilde{ctx} \models (v \Rightarrow u)

Definition 22 (Sound/Complete oracles):

  • Sound: accepts only checks that hold of (ctx,s)(ctx, s).
  • Complete: accepts every check that holds.

Theorem 23 (Safety from sound oracle): A sound oracle makes the selection safe regardless of pool quality: φ↓∧ctx⊨s\varphi_{\downarrow} \wedge ctx \models s and s∧ctx⊨φ↑s \wedge ctx \models \varphi_{\uparrow}.

Theorem 24 (Tightness from complete oracle): Completeness yields exactly the tight frontiers.

Theorem 29 (Exact recovery under coverage): Under disjunctive/conjunctive coverage (Definition 28), the search recovers the intent exactly.


Empirical Validation / Results

Expert-Adjudicated Study (20 non-zero-entropy cases)

The study used 64 established NL properties for 20 AWS resource types. Results:

QuantityCountFraction
Properties64—
Zero entropy (single eq class)4468.8%
Non-zero entropy (the benchmark)2031.2%
MV: safe, matches reference840%
MV: safe but conservative735%
MV: unsafe (admits a violation)525%
USC: safe, matches reference1050%
USC: safe but conservative840%
USC: unsafe210%
EG (ours): safe, matches reference1890%
EG (ours): safe but conservative210%
EG (ours): unsafe00%
Ablation (flat filter): safe, matches630%
Ablation: safe but conservative315%
Ablation: unsafe525%
Ablation: rejects every candidate630%

Scale Study (152 non-zero-entropy statements)

  • MV selects a candidate weaker than the oracle certified: 23.7% of statements
  • USC: 22.4%
  • EG: safe on at least 149/152 (98.0%) (counting 10 pools with no sufficient candidate as abstentions)

Oracle Soundness Measurement

Of 30 accepted checks on the 20 cases, the solver decided 23: 22 hold, 1 is wrong, 7 undecided (informal facts). The one wrong check did not affect EG's selection.

Case Study: API Gateway Logging

The statement "All methods in Amazon API Gateway stage has logging enabled" yielded 10 candidates in 4 clusters. The ambiguity residue was:

Amb=φ↑∧¬φ↓∧ctx=(¬M∨L)∧¬(M∧L)∧ctx=¬M∧ctx\text{Amb} = \varphi_{\uparrow} \wedge \neg\varphi_{\downarrow} \wedge ctx = (\neg M \vee L) \wedge \neg(M \wedge L) \wedge ctx = \neg M \wedge ctx

This identifies the ambiguity precisely: should a stage with no configured methods be compliant? EG selected the safe strong reading M∧LM \wedge L, while MV chose the weaker (unsafe) M⇒LM \Rightarrow L.


Theoretical and Practical Implications

Theoretical Significance

  1. One-sided guarantees: The framework formalizes the insight that verification-oriented adequacy is directional—sufficiency for enforcement, necessity for reliance. This aligns with contract-based design and weakest-precondition/strongest-postcondition calculi.

  2. Error asymmetry: Only a wrongly accepted oracle check can cost safety; wrongly rejected checks merely cost tightness. This one-sidedness is a direct consequence of the adjoint structure.

  3. Pool independence: Safety holds regardless of candidate pool quality—a poor pool yields slack frontiers, never unsafe ones. This separates EGs from statistical selection methods whose guarantees depend on pool quality.

  4. Machine-checked proofs: All results are verified in Lean 4 over an arbitrary Boolean algebra, providing formal assurance beyond the paper's prose.

Practical Implications

  1. Security-critical verification: For AWS cloud safety properties, EGs provide the first autoformalization method with certified safety guarantees, crucial for pre-deployment verification.

  2. Neuro-symbolic division of labor: The framework minimizes what the LLM must judge—each decision is a local, inspectable entailment check between two candidates, not a global judgment about a formula and a sentence.

  3. Actionable ambiguity: Unlike scalar uncertainty scores (e.g., semantic entropy), the ambiguity residue is a formula that names exactly what remains ambiguous, pointing directly to the clarifying question needed.

  4. Conservative defaults: Oracle uncertainty (no strict majority) makes results more conservative, trading tightness for safety.


Conclusion

Main takeaways:

  1. Entailment Graphs order LLM candidate formalizations by logical strength, enabling two directional searches that return the weakest sufficient and strongest necessary candidates—bracketing the statement's meaning.

  2. A sound entailment oracle suffices for safety; completeness buys only tightness. The only way safety can fail is a wrongly accepted edge check.

  3. The ambiguity residue is a formula that precisely characterizes what remains undetermined, and its unsatisfiability certifies contextual disambiguation.

  4. On AWS safety properties, EG selection is safe in all 20 expert-adjudicated cases, where baselines are unsafe in 10–25%. The graph structure—not access to an entailment oracle—delivers the guarantee.

Future directions:

  • Extending EGs to contract refinement (contravariant assumptions, covariant guarantees)
  • Using the ambiguity residue to seed clarification questions (implemented in parallel work by Barnaby et al.)
  • Generating more candidates guided by the residue to reduce ambiguity
  • Applying EGs to other domains with solver-decidable entailment relations

Related papers