Lesson 2 of 4 Responsible AI

Enforcing Safety and Privacy Policies with Amazon Bedrock Guardrails

This lesson explains how Amazon Bedrock Guardrails lets you define safety and privacy policies once and apply them to the inputs and outputs of all your generative AI applications.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish the guardrail policies, such as content filters, denied topics and sensitive information filters.
  • Describe where guardrails apply, including the ApplyGuardrail API.

Guardrail policies

Amazon Bedrock Guardrails checks both the prompts users send and the responses models return, using a set of policies that you configure. Content filters block hateful, insulting, sexual, violent and misconduct content, at a strength set separately for prompts and responses, and also cover images. The prompt attack filter detects jailbreak and prompt injection attempts. Denied topics block subjects you describe in plain language, such as investment advice for a banking assistant, and word filters block profanity and chosen words, such as competitor names.

Sensitive information filters detect personal information and custom patterns, then block it or mask it, for example replacing an email address with {EMAIL}. Contextual grounding checks block RAG answers that are not supported by the source documents or not relevant to the question, which catches hallucinations. Automated Reasoning checks use formal logic to verify that responses follow defined rules, such as an insurance policy's terms. The following table summarises the policies.

PolicyWhat it doesExample
Content filtersBlock hate, insults, sexual content, violence and misconduct, at a strength (none to high) set separately for prompts and responses; also cover imagesBlock abusive messages
Prompt attack filterDetects jailbreaks and prompt injection"Ignore your rules…"
Denied topicsTopics defined in plain language with sample phrases"Investment advice" for a banking assistant
Word filtersBlock profanity and custom wordsCompetitor names
Sensitive information filtersDetect PII and custom regex patterns, then block or mask themReplace an email with {EMAIL}
Contextual grounding checksBlock responses not grounded in the source or not relevant to the queryHallucinations in RAG answers
Automated Reasoning checksUse formal logic to verify responses follow defined policiesHR or insurance rules
Match the pairs

Guardrail policies

Exam skills 4.1.2

A mobile network operator is configuring a guardrail for its customer assistant. Match each requirement with the policy that meets it.

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

Where guardrails apply

Amazon Bedrock Guardrails can be applied in several contexts. The following list describes where guardrails apply and how blocked requests are handled.

  • Bedrock models, Agents and Knowledge Bases.
  • The ApplyGuardrail API evaluates any text without calling a model, so it also protects models on SageMaker AI, in other clouds or on premises.
  • Blocked requests return the message you configure; traces and metrics show which policy intervened.

The following diagram places the guardrail checks around a model.

Where Amazon Bedrock Guardrails apply. A guardrail checks the user's input before it reaches a Bedrock model, agent or knowledge base, and checks the model's output before it reaches the user, applying denied topics, content filters, word filters, sensitive information filters and grounding checks. The ApplyGuardrail API evaluates any text without calling a model, so it also protects models on SageMaker AI, in other clouds or on premises. Blocked requests return the configured message.
Guardrails check both directions.
True or false

Where guardrails apply

Exam skills 4.1.2

Check three claims about where Amazon Bedrock Guardrails can be used.

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

Configuring a guardrail for a banking assistant

A bank's assistant must stay helpful but safe. The team maps each requirement to a guardrail policy:

RequirementGuardrail policySetting
Never give investment adviceDenied topic"Investment advice: recommendations to buy or sell specific investments"
Resist attempts to override its rulesPrompt attack filterHigh strength on input
No abusive or violent content either wayContent filtersHigh for hate, insults, violence
Never show full account numbersSensitive information filterMask bank account numbers
Do not mention competitor banks by nameWord filterList of competitor names
Answers must come from the bank's documentsContextual grounding checkBlock answers below a grounding threshold

When a customer asks "Should I buy shares in ExampleCorp?", the guardrail intervenes and the customer sees the bank's configured message, such as "I cannot give investment advice, but I can connect you with an adviser." The same guardrail can protect a model hosted outside Bedrock through the ApplyGuardrail API.

Check yourself

Does a guardrail check what users send, what the model returns, or both?

Show answer

Both. A guardrail can evaluate the prompt before it reaches the model and the response before it reaches the user.

Exam Tips

Remember for the exam

  • To stop a banking chatbot from giving investment advice, define a denied topic.
  • To block jailbreak and injection attempts, use the prompt attack filter.
  • To mask email addresses and phone numbers in responses, use a sensitive information filter.
  • To detect hallucinations in RAG answers, use a contextual grounding check.
  • To apply guardrails to models outside Bedrock, use the ApplyGuardrail API.
  • To block competitor names or profanity, use word filters.