Enforcing Safeguards with Amazon Bedrock Guardrails
This lesson explains how Amazon Bedrock Guardrails, the exam guide's named tool for safeguards and responsible AI policies, enforce content, topic, privacy and accuracy policies on model inputs and outputs.
Learning outcomes
After completing this lesson, you will be able to:
- Configure guardrail policies.
- Apply guardrail versions to models, agents and knowledge bases.
- Place guardrails within a wider safeguard strategy.
Policies
A guardrail combines several policies. Content filters detect hate, insults, sexual content, violence, misconduct and prompt attacks (jailbreaks and prompt injection), with a strength per category for inputs and outputs, and can apply to text and images. Denied topics block subjects defined in natural language, such as investment advice. Word filters block specific words and profanity. Sensitive information filters detect PII types (names, emails, card numbers and many more) and custom regex patterns, and either block the request or mask the values. Contextual grounding checks score responses for grounding in the provided source and relevance to the query, blocking likely hallucinations in RAG. Automated Reasoning checks validate responses against formal rules derived from policy documents.
Guardrail policies
Applying guardrails
Guardrails are versioned. A guardrail version can be attached to InvokeModel and Converse calls, Bedrock Agents, knowledge base RetrieveAndGenerate calls and Flows. The ApplyGuardrail API evaluates any text without calling a model, so guardrails can protect self-hosted models, third-party models and data pipelines. Blocked requests return a configured message, and traces show which policy intervened. IAM condition keys can require a specific guardrail on every invocation.
The following diagram shows the input and output policies of a guardrail for a banking assistant.

Apply the guardrail
Guardrails in a wider safeguard strategy
Guardrails are one layer of protection, not the whole strategy. Sensitive data is redacted before it reaches training sets or retrieval indexes, so it cannot be learned or retrieved. Retrieval runs with least privilege, so users can retrieve only documents they are allowed to see. Outputs are validated for format and policy, guardrail interventions are logged and reviewed, and people remain in the loop for high-impact decisions. The following table maps common requirements to guardrail policies.
| Requirement | Guardrail policy |
|---|---|
| Block hateful or violent content | Content filters |
| Resist jailbreaks and prompt injection | Prompt attack filter |
| Never discuss a subject (for example, medical diagnosis) | Denied topics |
| Block competitor names or profanity | Word filters |
| Mask or block PII and custom identifiers | Sensitive information filters (mask or block, regex) |
| Reduce hallucinations in RAG answers | Contextual grounding check |
| Check answers against formal policy rules | Automated Reasoning checks |
| Protect a model hosted outside Bedrock | ApplyGuardrail API |
A banking assistant
A bank's assistant must not give investment advice, must mask account numbers and card numbers in responses, must refuse jailbreak attempts and must not invent policy details not in retrieved documents.
- Denied topic "investment advice" with example phrases.
- Sensitive information filter: credit card number in mask mode, plus a regex for the bank's account number format in mask mode.
- Prompt attack filter at high strength on inputs.
- Contextual grounding check with a grounding threshold of 0.8 on RAG responses.
- IAM policy requiring this guardrail identifier on all Bedrock invocations from the application role.
Prompt instructions alone ("do not give investment advice") can be bypassed; the guardrail enforces the policy outside the model.
Which guardrail detects hallucinations in RAG answers?
Show answer
The contextual grounding check.
Exam Tips
Remember for the exam
- Mask or block PII and custom patterns: sensitive information filters.
- Forbidden subjects: denied topics; jailbreaks: prompt attack filter.
- Hallucination in RAG: contextual grounding check.
- Models outside Bedrock or pipelines: ApplyGuardrail API.
- Require a guardrail on every call with IAM condition keys.