NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Grammars of Formal Uncertainty: When to Trust LLMs in Automated Reasoning Tasks

Debargha Ganguly, Vikash Singh, Sreehari Sankar, Biyao Zhang, Xuecen Zhang, Srinivasan Iyengar, Xiaotian Han, Amit Sharma, Shivkumar Kalyanaraman, Vipin Chaudhary

Abstract

Large Language Models (LLMs) are increasingly deployed to bridge the gap between natural language and formal logic through "autoformalization." However, the probabilistic nature of LLMs often clashes with the deterministic requirements of formal verification. This paper introduces a novel framework using Probabilistic Context-Free Grammars (PCFGs) to analyze the structural uncertainty of LLM-generated code. By quantifying syntactic patterns and recursive complexity, the authors demonstrate a high-precision method for predicting logical hallucinations, achieving an AUROC of over 0.93 in error detection and significantly reducing failure rates in safety-critical reasoning tasks.

Introduction: The Epistemological Gap

In the field of automated reasoning, Large Language Models (LLMs) serve as powerful translators, converting ambiguous natural language into machine-readable logic, such as SMT-LIB code for solvers like Z3. Yet, a fundamental "epistemological gap" persists: LLMs operate on probabilities, while formal methods demand absolute precision. Even a single misplaced operator in a generated proof can render a safety-critical verification useless.

Standard methods for measuring model confidence, such as token-level entropy (the probability of the next word), often fail to capture structural or semantic errors in code. To address this, the researchers propose a shift from analyzing individual tokens to analyzing the underlying grammar of the generated logic. By treating LLM outputs as samples from a structural distribution, they can identify the "syntactic fingerprints" of logical failure.

Methodology: PCFG-Based Uncertainty Quantification

The proposed framework moves beyond single-output analysis by utilizing ensembles. Instead of requesting a single proof, the system generates multiple samples and models them using a Probabilistic Context-Free Grammar (PCFG) based on the SMT-LIB standard. This approach allows for the derivation of 25 distinct uncertainty metrics, categorized into three primary areas:

  1. Grammar Entropy: This measures the variety and consistency of the logical rules the model selects across different samples. High entropy suggests the model is "guessing" between multiple conflicting logical structures.
  2. Spectral Radius: A metric used to quantify the recursive complexity and potential "loopiness" of the generated logic. This is particularly effective for identifying failures in arithmetic and recursive reasoning.
  3. NSUI (Novel Composite Metric): A fusion of entropy and structural complexity designed to provide a holistic view of the model's certainty.

To operationalize these signals, the authors implemented an Ensemble Fusion system. A lightweight machine learning model processes these grammar-based metrics to decide whether the system should trust the LLM's output or abstain from providing an answer—a process known as selective verification.

Experimental Setup and the "SMT Tax"

The study evaluated five frontier models—including o3-mini, DeepSeek-v3/R1, and Gemini 2.0 Flash—across four diverse reasoning benchmarks: ProofWriter (logical deduction), FOLIO (first-order logic), StrategyQA (multi-step world knowledge), and ProntoQA (synthetic logic).

The results revealed a phenomenon the authors call the "SMT Tax." While autoformalization significantly boosted accuracy on pure logic tasks (improving ProofWriter performance by up to 34.8%), it proved detrimental to tasks requiring broad world knowledge. In FOLIO, for instance, performance dropped by 44.5%. This suggests that the overhead of translating nuanced facts into rigid logic can introduce more errors than the solver eliminates, highlighting the need for selective application of formal methods.

Key Insights: Syntactic Fingerprints of Failure

The research demonstrates that when LLMs truly "understand" a problem, they produce consistent, high-probability rule sequences. Conversely, when a model is confused, it leaves identifiable syntactic fingerprints—atypical or convoluted grammar patterns that are detectable even when the individual tokens appear plausible.

Furthermore, the effectiveness of specific uncertainty signals is task-dependent. While grammar entropy is the strongest predictor for pure logical deduction, the spectral radius (measuring structural complexity) is a superior signal for arithmetic tasks. This suggests that neurosymbolic systems require a nuanced taxonomy of uncertainty, moving beyond simple aleatoric and epistemic splits to include "recursive-complexity" and "capacity-limited" uncertainty.

Results and Performance

The PCFG-based framework demonstrated superior calibration compared to traditional token-level uncertainty quantification:

  • High-Precision Detection: On the ProofWriter benchmark, the metrics achieved an AUROC of >0.93, allowing the system to distinguish between correct formalizations and hallucinations with near-perfect accuracy.
  • Error Reduction: By employing selective verification (abstaining from low-confidence results), the researchers reduced error rates by 14% to 100% across various tasks, with minimal impact on the total number of questions answered.
  • Structural Superiority: The results confirm that the structure of formal code provides a much richer signal for reliability than the probability of the words used to write it.

Conclusion and Future Directions

While the PCFG framework provides a robust mechanism for ranking the reliability of LLM outputs, the authors note that perfect calibration—where a confidence score maps exactly to a success rate—remains a challenge. Additionally, the current requirement for large ensemble sizes (N=100) introduces computational overhead.

Future research will focus on "modality-aware" architectures that align an LLM’s internal reasoning more closely with its external formal output. Reducing the number of samples required to extract these grammar signals will be essential for deploying this framework in real-time engineering and safety-critical applications. Ultimately, this work provides a vital roadmap for building neurosymbolic systems that know when to speak and when to remain silent.

Summary updated

BibTeX
@inproceedings{ganguly2025grammars,
  author = {Debargha Ganguly and Vikash Singh and Sreehari Sankar and Biyao Zhang and Xuecen Zhang and Srinivasan Iyengar and Xiaotian Han and Amit Sharma and Shivkumar Kalyanaraman and Vipin Chaudhary},
  title = {{Grammars of Formal Uncertainty: When to Trust LLMs in Automated Reasoning Tasks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=QfKpJ00t2L},
}
Figure