Shh, don't say that! Domain Certification in LLMs

Cornelius Emde, Alasdair Paren, Preetham Arvind, Maxime Guillaume Kayser, Tom Rainforth, Thomas Lukasiewicz, Philip Torr, Adel Bibi

Abstract

Large Language Models (LLMs) are increasingly deployed for narrow, domain-specific tasks, yet they remain susceptible to adversarial "jailbreaks" that elicit off-topic or harmful content. We present "domain certification," a framework that provides provable guarantees on the probability of out-of-domain (OOD) outputs. Our proposed algorithm, VALID (Verified Adversarial LLM Output via Iterative Dismissal), utilizes a dual-model rejection sampling approach to bound OOD generation probabilities regardless of the user's prompt. Experiments across medical and literary domains demonstrate that VALID can reduce OOD generation probability by factors as large as $10^{24}$ while maintaining high utility on target benchmarks.

1. The Vulnerability of Specialized LLMs

Today, organizations frequently fine-tune general-purpose foundation models for specialized applications, such as medical Q&A or technical support. However, because the underlying base model retains broad knowledge, it remains vulnerable to adversarial prompts designed to bypass safety guardrails like Reinforcement Learning from Human Feedback (RLHF).

Current defenses often result in a "whack-a-mole" scenario where developers patch specific vulnerabilities only for attackers to discover new prompt injection techniques. There are currently no provable guarantees that a deployed LLM will remain within its designated domain. This work addresses this gap by asking: Can we mathematically certify that an LLM-based system will generate out-of-domain text with only a vanishingly small probability, even under worst-case adversarial attacks?

2. The VALID Framework

To provide these guarantees, we introduce VALID (Verified Adversarial LLM Output via Iterative Dismissal). The system employs a two-model architecture using rejection sampling:

  1. The Generalist ($L$): A high-capacity LLM that generates initial response drafts.
  2. The Guide ($G$): A smaller, specialized model trained exclusively on in-domain data (e.g., medical literature).

When a user submits a prompt, the Generalist drafts a response. VALID then evaluates the length-normalized log-likelihood ratio between the two models. If the response is in-domain, the Guide recognizes the patterns and assigns a high probability. If the response is OOD, the Guide assigns a near-zero probability, causing the ratio to spike.

The log-likelihood ratio between the generalist and guide models increases with sequence length, allowing for a linear boundary $kN_y$ to separate target domain content from OOD content.

By enforcing a threshold $k$ on this ratio, we can mathematically prove an upper bound on the probability of the system generating any specific OOD response. Length normalization is critical here; without it, the natural drop in probability for longer sequences would bias the system against multi-sentence responses.

3. Experimental Evaluation

VALID was evaluated across three domains: Shakespearean text, Computer Science news, and Medical QA (PubMedQA). To assess performance under certification, we utilized modified benchmarks (PubMedQA@$\epsilon$) where a response is only considered correct if it is both accurate and passes the VALID certification check.

Key Results

  • Probability Constriction: For OOD samples in the medical domain, VALID reduced the likelihood of generation by a median factor of $10^{24}$ compared to an unprotected model.
  • Certification with Low Utility Cost: At a strict certification level of $\epsilon = 10^{-5}$, the system maintained a score of 66.7% on PubMedQA, compared to the unconstrained model's 73.4%. This was achieved while falsely rejecting only 15% of valid in-domain answers.
  • Adversarial Robustness: To bypass VALID, an attacker must force the Generalist to generate a harmful output while simultaneously suppressing its probability to stay below the threshold $k$—a counter-intuitive and difficult task for prompt engineering.

4. Discussion and Limitations

While VALID provides strong theoretical guarantees, it faces certain practical challenges. The Guide model currently evaluates only the response, meaning it may be "blind" to context (e.g., a tax bot correctly answering a hygiene question with a generic phrase like "once a year"). Additionally, the requirement for a second model and potential multiple drafting iterations increases inference latency.

Future research will explore larger guide models to reduce false rejection rates and investigate non-linear normalization thresholds to further tighten the mathematical bounds of domain certification.

Summary updated

BibTeX
@inproceedings{emde2025shh,
  author = {Cornelius Emde and Alasdair Paren and Preetham Arvind and Maxime Guillaume Kayser and Tom Rainforth and Thomas Lukasiewicz and Philip Torr and Adel Bibi},
  title = {{Shh, don't say that! Domain Certification in LLMs}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=F64wTvQBum},
}
Figure