Beaver: An Efficient Deterministic LLM Verifier

Tarun Suresh, Nalin Wadhwa, Debangshu Banerjee, Gagandeep Singh

As Large Language Models (LLMs) move from research curiosities to the backbone of production systems, the stakes for safety have never been higher. Whether it's leaking private emails, generating insecure code, or spewing toxic content, "tail risks"—rare but high-impact failures—are the primary hurdle for safe deployment.

Standard safety evaluations usually rely on sampling: you prompt the model a few dozen times and see if anything bad happens. But for a model that might be queried millions of times, a 1-in-1,000 failure rate is a disaster, yet it's nearly impossible to catch with ad-hoc sampling.

Enter BEAVER, a new framework from researchers at UIUC that moves beyond "fingers-crossed" sampling toward deterministic, sound verification.

TL;DR

BEAVER is the first practical framework to compute provably sound probability bounds on whether an LLM will satisfy a safety property. By using a branch-and-bound approach to explore the model's output space, it identifies 2.5–3.3x more risky prompts than standard sampling while using only 1/10th of the compute budget.

What Problem Does This Paper Address?

The core challenge is that LLMs are probabilistic. For any given prompt, there isn't just one output; there is a massive, branching tree of possible token sequences, each with its own probability.

Current safety methods like red-teaming or benchmarking are "ad-hoc." They provide an intuition of model behavior but no formal guarantees. If a model passes a benchmark, does that mean it's safe, or just that we didn't sample the specific sequence that triggers a violation?

The authors formalize this as a verification problem: given a model $M$, a prompt $p$, and a safety property $\Phi$, can we compute the exact probability $P$ that the model's output satisfies $\Phi$? Because the output space is exponentially large, computing $P$ exactly is impossible. BEAVER instead computes sound interval bounds $[P_{LB}, P_{UB}]$, ensuring the true probability always lies within this range.

Methods

BEAVER treats LLM generation as a search problem. It uses a branch-and-bound algorithm built on two novel data structures:

  1. Token Trie ($\mathcal{T}$): A prefix tree that tracks all explored token sequences that satisfy the safety property, along with their cumulative probabilities.
  2. Frontier ($\Psi$): A set of incomplete sequences that are candidates for further expansion.
BEAVER workflow for computing sound probability bounds.

The Power of Prefix Closure

The key insight is that most safety properties are prefix-closed (modeled as $G \phi$ in Linear Temporal Logic). This means if a sequence is "bad," any extension of it is also "bad." If a model starts leaking an email address in the first five tokens, no amount of "good" tokens later can fix that violation.

This allows BEAVER to aggressively prune the search space. As soon as a prefix violates the property, the algorithm stops exploring that branch and subtracts its probability mass from the upper bound ($P_{UB}$).

Soundness and Optimizations

To keep the search tractable, BEAVER employs a Max-$\mu$ selection strategy, greedily expanding the highest-probability sequences first to tighten the bounds as quickly as possible. It also handles the massive vocabulary of modern LLMs (often >150k tokens) by using top-p/top-k filtering and a "pruned mass accumulator" to ensure that even the probability mass of unvisited tokens is accounted for in the final bounds.

Datasets

The authors evaluated BEAVER across 12 open-weight models (including Llama 3, Qwen 2.5/3, and Gemma 3) on four distinct safety tasks:

  • Privacy Leakage: Detecting if the model leaks specific (name, email) pairs from the Enron corpus.
  • Insecure Code Generation: Using CyberSecEval to find CWE (Common Weakness Enumeration) patterns in generated Rust code.
  • Stereotype Bias: Identifying stereotypical statements from the DecodingTrust benchmark.
  • Toxicity: Using the Detoxify classifier on prompts from RealToxicityPrompts.
  • GSM-Symbolic: A mathematical reasoning task used to show that BEAVER also works for verifying correctness, not just safety.

Key Insights and Ideas

  • Sampling is a Poor Primitive for Risk: The paper demonstrates that sampling is structurally disadvantaged. It frequently rediscovers high-probability "safe" sequences while missing the lower-probability "unsafe" sequences that actually constitute the tail risk.
  • Risk is Highly Asymmetric: A model that is "safe" on one task might be highly "risky" on another. For example, Qwen3-4B showed high privacy risk but was nearly safe regarding toxicity. Single-number safety scores fail to capture these nuances.
  • Alignment vs. Scale: Interestingly, model size isn't a perfect predictor of safety. In the Qwen family, newer, smaller models were sometimes safer than older, larger ones due to better alignment, but these improvements were task-specific.

Key Results

BEAVER's efficiency is its standout feature. In head-to-head comparisons:

  • Better Detection: BEAVER identified significantly more "risky" instances (defined as prompts with a $>10\%$ violation probability) than the Sampling Verifier (SV).
  • Compute Efficiency: Even when the sampling baseline was given 10x the compute budget, BEAVER still surfaced 2.5–3.3x more risky instances.
  • Tight Bounds: On the GSM-Symbolic task, BEAVER achieved bounds roughly 7x tighter than sampling for the same budget.
Safety profiles across 12 models and four tasks.

As seen in the results table above, the Risky Distribution Ratio (RDR%) varies wildly across models and tasks, proving that deterministic verification is necessary to understand a model's true safety profile.

Limitations and Future Work

While a major step forward, BEAVER has a few constraints:

  • White-box Access: It requires access to the full token probability distributions, making it currently incompatible with closed-API models like GPT-4 (unless providers expose these logits).
  • Property Scope: It primarily targets prefix-closed properties. While the authors show how to adapt it for final-state checks (like math correctness), extending it to more complex temporal logic remains future work.
  • Selection Heuristics: The current greedy strategy works well, but integrating learned "value functions" could further accelerate convergence on very long generation tasks.

By providing a way to actually calculate risk rather than just estimate it, BEAVER offers a path toward truly principled safety assessments for the LLMs we rely on every day.

Summary updated

BibTeX
@inproceedings{suresh2026beaver,
  author = {Tarun Suresh and Nalin Wadhwa and Debangshu Banerjee and Gagandeep Singh},
  title = {{Beaver: An Efficient Deterministic LLM Verifier}},
  booktitle = {VerifAI-2 @ ICLR},
  year = {2026},
  url = {https://openreview.net/forum?id=xO3efBXHM9},
}
Figure