Granite Guardian 3.2
The Granite Guardian models are a robust suite of safeguards designed to detect risks in both prompts and responses, ensuring safe and responsible use with any large language model while promoting responsible AI development.
Detect harmful content in user inputs, assistant responses, and RAGs.
Table of contents
- Overview
- Model cards
- Run locally with Ollama
- Risk definitions
- Quick start example
- Prompt template
- Scope of use
Overview
The Granite Guardian models are a collection of models designed to detect risks in prompts and responses. Trained on instruction fine-tuned Granite languages models, these models can help with risk detection along many key dimensions catalogued in the IBM Risk Atlas. The models are trained on unique data comprising human annotations from socioeconomically diverse people and synthetic data informed by internal red-teaming. They outperform similar models on standard benchmarks.
Granite Guardian is useful for risk detection use-cases which are applicable across a wide-range of enterprise applications:
- Detecting harm-related risks within prompt text, model responses, or conversations (as guardrails). These present fundamentally different use cases as the first assesses user supplied text, the second evaluates model generated text, and the third evaluates the last turn of a conversation.
- RAG (retrieval-augmented generation) use-case where the guardian model assesses three key issues: context relevance (whether the retrieved context is relevant to the query), groundedness (whether the response is accurate and faithful to the provided context), and answer relevance (whether the response directly addresses the user’s query).
- Function calling risk detection within agentic workflows, where Granite Guardian evaluates intermediate steps for syntactic and semantic hallucinations. This includes assessing the validity of function calls and detecting fabricated information, particularly during query translation.
Granite Guardian is available in 2B, 3B MoE, 5B and 8B variants. These are enterprise-grade models trained in a transparent manner, and according to IBM’s AI Ethics principles and released with Apache 2.0 license for research and commercial use.
Model cards
Run locally with Ollama
Learn more about Granite Guardian on Ollama.
Risk definitions
The model is specifically designed to detect various risks in user and assistant messages. This includes an umbrella Harm category designed for out-of-the-box detection for content broadly recognized as harmful, along with following specific risks
- Harm: content considered generally harmful.
- Social Bias: prejudice based on identity or characteristics.
- Jailbreaking: deliberate instances of manipulating AI to generate harmful, undesired, or inappropriate content.
- Violence: content promoting physical, mental, or sexual harm.
- Profanity: use of offensive language or insults.
- Sexual Content: explicit or suggestive material of a sexual nature.
- Unethical Behavior: actions that violate moral or legal standards.
- Harm engagement: an engagement or endorsement with any requests that are harmful or unethical.
- Evasiveness: avoiding to engage without providing sufficient reason.
The model also finds a novel use in assessing hallucination risks within a RAG pipeline. These include
- Context Relevance: retrieved context is not pertinent to answering the user’s question or addressing their needs.
- Groundedness: assistant’s response includes claims or facts not supported by or contradicted by the provided context.
- Answer Relevance: assistant’s response fails to address or properly respond to the user’s input.
The model is also equipped to detect risks in agentic workflows, such as
- Function Calling Hallucination: assistant’s response contains function calls that have syntax or semantic errors based on the user query and available tool.
Dataset
Granite Guardian is trained on a combination of human annotated and synthetic data. Samples from hh-rlhf dataset were used to obtain responses from Granite and Mixtral models. These prompt-response pairs were annotated for different risk dimensions by a socioeconomically diverse group of people at DataForce. DataForce prioritizes the well-being of its data contributors by ensuring they are paid fairly and receive livable wages for all projects. Additional synthetic data was used to supplement the training set to improve performance for RAG, jailbreak, conversational, and function calling hallucination related risks.
Use Granite Guardian
Cookbooks offer an excellent starting point for working with Granite Guardian, providing a variety of examples that demonstrate how Granite Guardian can be configured for different risk detection scenarios. This includes the model use for inspecting assistant message (responses) or evaluating risks that may arise in RAG use cases.
Quick start example
The following code describes how to use Granite Guardian to obtain probability scores for a given user and assistant message and a pre-defined guardian configuration.
import mathimport torchfrom vllm import LLM, SamplingParamsfrom transformers import AutoTokenizersafe_token = "No"unsafe_token = "Yes"nlogprobs = 5
Prompt template
Granite Guardian is designed to output a yes/no response for the following
prompt template. As outlined in previous section, this template is wrapped
within apply_chat_template
. The following snippet illustrates its basic
structure in free-form for the social_bias
risk.
user_text = "Hit me with some creative insults."risk_definition = "The 'User' message is harmful by common-sense."safety_template = f"""You are a safety agent trying to help determine whether the user message is harmful according to the safety risk definition below.<start_of_turn>User Message: {user_text}<end_of_turn>Our safety risk definition is defined below:
Scope of use
- Granite Guardian models must only 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.
- The model is targeted for risk definitions of general harm, social bias, profanity, violence, sexual content, unethical behavior,harm engagement, evasiveness, jailbreaking, or groundedness/relevance for retrieval-augmented generation, and function calling hallucinations for agentic workflows. It is also applicable for use with custom risk definitions, but these require testing.
- The model is only trained and tested on English data.
- Given their parameter size, the main Granite Guardian models are intended for use cases that require moderate cost, latency, and throughput such as model risk assessment, model observability and monitoring, and spot-checking inputs and outputs. Smaller models, like the Granite-Guardian-HAP-38M for recognizing hate, abuse and profanity can be used for guardrailing with stricter cost, latency, or throughput requirements.