Applying Safety and Privacy Policies with Amazon Bedrock Guardrails
This lesson explains how Amazon Bedrock Guardrails apply configurable safety and privacy policies to model inputs and outputs, protecting generative AI applications from manipulation and from harmful, private or invented content.
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.
- Explain how the bedrock:GuardrailIdentifier condition key enforces guardrail use.
Guardrail policies
A Bedrock guardrail combines several policies, each evaluated on prompts, responses or both. Content filters detect hate, insults, sexual content, violence and misconduct at an adjustable strength, in text and images. The prompt attack filter detects jailbreak attempts and prompt injection. Denied topics block subjects you describe in natural language, such as investment advice, and word filters block profanity and words you list.
Sensitive information filters detect personally identifiable information (PII) and custom regular expression patterns, and either block the content or mask the values. Contextual grounding checks detect hallucinations by checking that a response is supported by the source material and relevant to the question. Automated reasoning checks use formal logic to verify responses against policy rules you define. The following table summarises the policies.
| Policy | What it does |
|---|---|
| Content filters | Hate, insults, sexual content, violence, misconduct; adjustable strength; covers images |
| Prompt attack | Detects jailbreaks and prompt injection |
| Denied topics | Topics defined in natural language |
| Word filters | Profanity and custom words |
| Sensitive information filters | Block or mask PII and custom regex patterns |
| Contextual grounding checks | Detect hallucinations against source material |
| Automated reasoning checks | Verify responses against formal policy rules |
Which guardrail policy?
Where guardrails apply
A guardrail is defined once, with its content filters, denied topics, word filters, sensitive information filters, contextual grounding checks and automated reasoning checks, and is then versioned. The same guardrail can be applied wherever model input and output pass, so one policy protects every application that uses it. The following list describes where guardrails can be applied.
- Model invocations through
InvokeModelandConverse, by guardrail ID and version. - Bedrock Agents and Knowledge Bases.
- The ApplyGuardrail API, for any text, including from SageMaker AI or non-AWS models.
The following diagram matches four requirements for a banking assistant to the Bedrock guardrail policy that meets each.

Where guardrails apply
Enforcing guardrails
An IAM condition on bedrock:GuardrailIdentifier makes model invocations without the required guardrail fail, and an SCP can apply the same requirement across accounts. Guardrail versions are immutable, so applications reference a tested version and a new version is promoted deliberately.
Making guardrails mandatory
A guardrail for a customer-facing assistant
A bank's assistant must refuse investment advice, resist jailbreaks, never reveal account numbers, and stay grounded in the bank's documentation. One guardrail expresses all four requirements:
aws bedrock create-guardrail --name retail-assistant \
--blocked-input-messaging "Sorry, I cannot help with that." \
--blocked-outputs-messaging "Sorry, I cannot share that." \
--topic-policy-config '{"topicsConfig":[{"name":"InvestmentAdvice","type":"DENY",
"definition":"Recommendations about buying or selling specific investments."}]}' \
--content-policy-config '{"filtersConfig":[{"type":"PROMPT_ATTACK","inputStrength":"HIGH","outputStrength":"NONE"}]}' \
--sensitive-information-policy-config '{"piiEntitiesConfig":[
{"type":"US_BANK_ACCOUNT_NUMBER","action":"BLOCK"},{"type":"EMAIL","action":"ANONYMIZE"}]}' \
--contextual-grounding-policy-config '{"filtersConfig":[{"type":"GROUNDING","threshold":0.8}]}'The application references the guardrail ID and version in every InvokeModel or Converse call, and an IAM condition on bedrock:GuardrailIdentifier makes calls without it fail.
Which guardrail filter blocks jailbreak and prompt injection attempts?
Show answer
The prompt attack filter.
Exam Tips
Remember for the exam
- To block jailbreak and prompt injection attempts, use the Guardrails prompt attack filter.
- To mask PII in model responses, use a Guardrails sensitive information filter.
- To detect hallucinations in RAG answers, use a contextual grounding check.
- To use guardrails with models outside Bedrock, use the ApplyGuardrail API.
- To require a guardrail on every invocation, use the bedrock:GuardrailIdentifier condition key.