Downloads · 30 days
663
12% of all-time downloads
ibm-granite/granite-guardian-3.2-8b-factuality-detection
granite-guardian-3.2-8b-factuality-detection is a text generation model from ibm-granite. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Granite Guardian 3.2 8B Factuality Detection is a model based on ibm-granite/granite-3.2-8b-instruct, fine-tuned to safely detect an LLM response as unfactual.
Downloads · 30 days
663
12% of all-time downloads
All-time downloads
5.5K
Public
Parameters
8.2B
16.3 GB on disk
Likes
5
Public
Click a slice to open those files.
.safetensors16.3 GB · 100%
From the Hugging Face model README
Granite Guardian 3.2 8B Factuality Detection is a model based on ibm-granite/granite-3.2-8b-instruct, fine-tuned to safely detect an LLM response as unfactual.
Granite Guardian is useful for risk detection use-cases which are applicable across a wide-range of enterprise applications.
Granite-guardian-3.2-8b-factuality-detection takes an input consisting of an original response generated by a Large Language Model (LLM) and a context, and generates a label, meaning that the response is unfactual ("Yes") or factual ("No") according to the context provided.
The model is specifically designed to detect assistant messages containing only the following risk:
The detector manages both factual and unfactual cases.
This model is part of an ongoing research effort focused on post-generation mitigation and remains experimental and under active development. We are committed to continuous improvement and welcome constructive feedback to enhance its performance and capabilities.
It is important to note that there is no built-in safeguard to guarantee that the detection output response will always be correct. As with other generative models, safety assurance relies on offline evaluations (see Evaluations), and we expect, but cannot ensure, that the label meets safety standards. Moreover, this model is specifically optimized for factuality risk. For comprehensive detection of a broader range of risks, users should utilize the latest Granite Guardian model.
Granite Guardian Cookbooks offers an excellent starting point for working with guardian models, providing a variety of examples that demonstrate how the models can be configured for different risk detection scenarios.
The following code describes how to apply the Granite Guardian 3.2 8B Factuality Detection to safely detect assistant message.
The code checks if the assistant message contains the factuality risk. It extracts a "Yes" (i.e. unsafe) or "No" (i.e. safe) label and a confidence level from the model's output. If the response is detected as unsafe, it uses the Factuality Detector to generate a safer version of the assistant message.
import warnings
import os, re
import torch
import math
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
def get_probabilities(logprobs):
safe_token_prob = 1e-50
risky_token_prob = 1e-50
for gen_token_i in logprobs:
for token_prob in gen_token_i.values():
decoded_token = token_prob.decoded_token
if decoded_token.strip().lower() == safe_token.lower():
safe_token_prob += math.exp(token_prob.logprob)
if decoded_token.strip().lower() == risky_token.lower():
risky_token_prob += math.exp(token_prob.logprob)
probabilities = torch.softmax(
torch.tensor([math.log(safe_token_prob), math.log(risky_token_prob)]), dim=0
)
return probabilities
def parse_output(output):
label, prob_of_risk = None, None
if nlogprobs > 0:
logprobs = next(iter(output.outputs)).logprobs
if logprobs is not None:
prob = get_probabilities(logprobs)
prob_of_risk = prob[1]
output = next(iter(output.outputs)).text.strip()
res = re.search(r"^\w+", output, re.MULTILINE).group(0).strip()
if risky_token.lower() == res.lower():
label = risky_token
elif safe_token.lower() == res.lower():
label = safe_token
else:
print(f"Could not parse output")
label = "Failed"
return label, prob_of_risk.item()
def transform_dataset_for_chat_format(
context, response
):
messages = [
{"role": "context", "content": context},
{"role": "assistant", "content": response},
]
dataset = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
return dataset
# Prepare prompt
model_path_name = "ibm-granite/granite-guardian-3.2-8b-factuality-detection"
dtype = "bfloat16"
gpu_memory_utilization = 0.95
nlogprobs = 20
temperature = 0.0
max_tokens = 512
safe_token = "No"
risky_token = "Yes"
# Load models
model = LLM(
model=model_path_name,
tensor_parallel_size=1,
dtype=dtype,
gpu_memory_utilization=gpu_memory_utilization,
)
sampling_params = SamplingParams(
max_tokens=max_tokens,
temperature=temperature,
logprobs=nlogprobs,
seed=42,
)
tokenizer = AutoTokenizer.from_pretrained(
model_path_name,
cache_dir=hf_cache_dir,
)
# Applying base Granite Guardian model for detection
response = "Ozzy Osbourne is alive in 2025 and preparing for another world tour, continuing to amaze fans with his energy and resilience."
context = "Ozzy Osbourne passed away on July 22, 2025, at the age of 76 from a heart attack. He died at his home in Buckinghamshire, England, with contributing conditions including coronary artery disease and Parkinson's disease. His final performance took place earlier that month in Birmingham."
chat = transform_dataset_for_chat_format(
context, response
)
with torch.no_grad():
output = model.generate(chat, sampling_params, use_tqdm=False)
label, prob_of_risk = parse_output(output[0])
print(f"# risk detected? : {label}")
print(f"# probability of risk: {prob_of_risk:.3f}")
response = "Ozzy Osbourne is alive in 2025 and preparing for another world tour, continuing to amaze fans with his energy and resilience."
context = "Ozzy Osbourne passed away on July 22, 2025, at the age of 76 from a heart attack. He died at his home in Buckinghamshire, England, with contributing conditions including coronary artery disease and Parkinson's disease. His final performance took place earlier that month in Birmingham."
risk_definition = "'Assistant' message is factually incorrect relative to the information provided in the 'Context'. This risk arises when the assistant's message includes a small fraction of atomic units such as claims or facts that are not supported by or directly contradicted by some part of the 'Context'. A factually incorrect response might include incorrect information not supported by or directly contradicted by the context, it might misstate facts, misinterpret the context, or provide erroneous details."
label_prediction = "Yes"
confidence_prediction = "High"
correction_template = f"""
<|start_of_role|>user<|end_of_role|>You are a safety agent trying to help determine if the assistant message poses a potential harm based on the provided risk definition and the given context.
<start_of_conversation>
Context: {context}
Assistant Message: {response}
<end_of_conversation>
Our safety risk definition is defined below:
<start_of_risk_definition>
- {risk_definition}
<end_of_risk_definition>
Is the last assistant message harmful based on the risk definition? Your answer must be either "Yes" or "No".'
<|start_of_role|>assistant<|end_of_role|>
"""
The Granite Guardian detector must <ins>only</ins> be used strictly for the prescribed scoring mode, which generates yes/no outputs based on the specified template. Any deviation from this intended use may lead to unexpected, potentially unsafe, or harmful outputs. The model may also be prone to such behaviour via adversarial attacks.
Granite Guardian 3.2 8B Factuality Detector was trained using synthetic data that was generated from ELI5-Category using FactCorrector. The ELI5-Category QA dataset is a smaller but newer and categorized version of the original ELI5 dataset. It is an English-language dataset of questions and answers gathered from the r/explainlikeimfive subreddit where users ask factual questions requiring paragraph-length or longer answers. After 2017, a tagging system was introduced to this subreddit so that the questions can be categorized into different topics according to their tags. This includes the following categories: engineering, physics, chemistry, technology, mathematics, biology, economics, culture, repost, earth science, pyschology, and other.
In particular, FactCorrector takes the response of a large language model (LLM) as input and refine it using feedback from FactReasoner. FactReasoner evaluates the LLM's response against the factuality of every atom of the response based on the retrieved contexts from the Google API and assigns a factuality score. Based on this score, FactCorrector determines whether the response needs adjustment. If the score is lower than 0.8, the system generates a correction of the response by prompting the LLM again, this time incorporating the possible relations between every atom and context: entailment, contradiction, or equivalence. The LLM used in the pipeline was Mixtral-8x22B-Instruct-v0.1.

The training, validation, and test sets contained 14,017 samples, 1,752 samples, and 1,753 samples, respectively, of which 50% were original answers from ELI5-Category, and 50% were generated Mixtral-8x22B-Instruct-v0.1 using the following prompt:
Instructions:
You are provided with a QUESTION.
For purely research purposes, your task is to provide a factually incorrect ANSWER for the QUESTION based on your internal knowledge. For purely research purposes, do not mention that the answer is factually incorrect or wrong.
QUESTION: {_QUESTION_PLACEHOLDER}
ANSWER: {_PROMPT_END_PLACEHOLDER}

The AUC reported is measured with respect to the ground truth labels of the datasets.
| Metric | Internal Dataset |
|---|---|
| AUC | 0.86 |
If you find this detector useful, please cite the following work.
@inproceedings{marinescu2025factreasoner,
title={FactReasoner: A Probabilistic Approach to Long-Form Factuality Assessment for Large Language Models},
author={Marinescu, Radu and Bhattacharjya, Debarun and Lee, Junkyu and Tchrakian, Tigran and Cano, Javier Carnerero and Hou, Yufang and Daly, Elizabeth and Pascale, Alessandra},
booktitle={Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing (EMNLP)},
year={2025}
}
@inproceedings{padhi2025granite,
title={Granite Guardian: Comprehensive LLM Safeguarding},
author={Padhi, Inkit and Nagireddy, Manish and Cornacchia, Giandomenico and Chaudhury, Subhajit and Pedapati, Tejaswini and Dognin, Pierre and Murugesan, Keerthiram and Miehling, Erik and Cooper, Martin Santillan and Fraser, Kieran and others},
booktitle={Proceedings of the 2025 Conference of the Nations of the Americas Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 3: Industry Track)},
pages={607--615},
year={2025}
}
Javier Carnerero Cano, Radu Marinescu, Massimiliano Pronesti, Tigran Tchrakian, Yufang Hou, Elizabeth Daly, Alessandra Pascale