Lesson 4 of 5 Compliance, Auditing and AI Safeguards

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.

Match the pairs

Guardrail policies

Exam skills 4.3.9

Match each requirement with the Bedrock Guardrails policy that meets it.

Log in to try this activity Interactive activities are free with an account.

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.

The banking assistant's guardrail. On input, the prompt attack filter at high strength refuses jailbreaks and the denied topic blocks investment advice. On output, sensitive information filters mask card numbers and the bank's account number format, and a contextual grounding check at 0.8 blocks answers not supported by the retrieved documents. An IAM policy requires this guardrail on every invocation.
The scenario is illustrative.
Scenario questions

Apply the guardrail

Exam skills 4.3.9

Choose how to apply a guardrail in each architecture.

Log in to try this activity Interactive activities are free with an account.

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.

RequirementGuardrail policy
Block hateful or violent contentContent filters
Resist jailbreaks and prompt injectionPrompt attack filter
Never discuss a subject (for example, medical diagnosis)Denied topics
Block competitor names or profanityWord filters
Mask or block PII and custom identifiersSensitive information filters (mask or block, regex)
Reduce hallucinations in RAG answersContextual grounding check
Check answers against formal policy rulesAutomated Reasoning checks
Protect a model hosted outside BedrockApplyGuardrail API
Worked example

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.

Check yourself

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.