Lesson 1 of 4 Input and Output Safety Controls

Configuring Amazon Bedrock Guardrails Policies

This lesson describes each Amazon Bedrock Guardrails policy, which applies configurable safety and privacy controls to inputs and outputs independently of the model and prompt, and how guardrails are applied and versioned.

Learning outcomes

After completing this lesson, you will be able to:

  • Configure content filters and prompt attack filters.
  • Configure denied topics, word filters and sensitive information filters.
  • Use contextual grounding and Automated Reasoning checks.
  • Apply guardrail versions in API calls and with ApplyGuardrail.

Content filters and prompt attacks

Content filters detect and block harmful content in six categories: hate, insults, sexual, violence, misconduct (criminal activity) and prompt attack. Each category has a filter strength (none, low, medium or high) set separately for inputs and outputs; higher strength blocks more content, including lower-confidence detections, at the risk of more false positives. Content filters can also evaluate images for supported categories. The prompt attack filter detects jailbreak attempts, prompt injection and attempts to extract the system prompt, and applies to user input.

Denied topics, word filters and sensitive information

Denied topics are defined in natural language with a name, a definition and sample phrases, such as "Investment advice: recommendations about buying or selling specific securities". The guardrail blocks inputs or outputs about the topic regardless of wording. Word filters block exact words and phrases, such as competitor names, plus a managed profanity list.

Sensitive information filters detect personally identifiable information (PII) entity types, such as names, email addresses, phone numbers, credit card numbers and national identifiers, and custom regular expressions for organization-specific data such as account numbers. Each type is set to block the whole request or response, or to mask (anonymise) the value, replacing it with a placeholder such as {EMAIL}.

The following diagram maps each requirement to a policy in the guardrail.

One guardrail covering four banking requirements: a denied topic for investment advice, a sensitive information filter that masks card numbers in outputs, content filters for insults and hate on inputs and outputs, and a contextual grounding check with grounding and relevance thresholds. It is attached by version to the RetrieveAndGenerate calls.
One guardrail can combine every policy type.
Sort into groups

Which guardrail policy?

Exam skills 3.1.1 · 3.1.2

Choose the Bedrock Guardrails policy that implements each requirement.

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

Grounding and Automated Reasoning checks

Contextual grounding checks evaluate a response against a reference source, such as retrieved passages, and the user's query. They compute a grounding score (is the response supported by the source?) and a relevance score (does it answer the query?), and block responses below configured thresholds between 0 and 0.99. Automated Reasoning checks validate responses against a policy that Bedrock translates from documents (for example an HR or eligibility policy) into formal logic, and return findings that show whether a response is valid, invalid or unsupported, with explanations, so the application can correct or flag it.

The following diagram shows a contextual grounding check blocking a response.

How a contextual grounding check decides. It compares the response with the retrieved source and the user's query, computes a grounding score and a relevance score, and blocks the response when either falls below its threshold. Here the response answers the question but is poorly supported by the source, so it is blocked.
The scores and threshold are illustrative.
True or false

Grounding and Automated Reasoning

Exam skills 3.1.3

Check four claims about contextual grounding and Automated Reasoning checks.

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

Applying guardrails

A guardrail is created as a working draft and published as numbered versions. Applications attach a guardrail ID and version to Converse, InvokeModel, RetrieveAndGenerate, agents and flows; when it intervenes, the response is replaced with a configurable blocked message and the stop reason indicates a guardrail intervention. Trace output shows which policy triggered. In Converse, guardContent blocks mark which parts of the input to evaluate, so system instructions or trusted context are not filtered, and grounding sources and queries are marked for grounding checks.

The ApplyGuardrail API evaluates any text against a guardrail without invoking a model, so the same policies protect models on SageMaker AI, third-party providers, or intermediate steps of an agent. For streaming, guardrails evaluate output in chunks, synchronously or asynchronously. Guardrails can use cross-Region profiles for capacity and broader language support.

resp = brt.apply_guardrail(
    guardrailIdentifier="gr-abc123", guardrailVersion="4", source="OUTPUT",
    content=[{"text": {"text": model_output}}],
)
if resp["action"] == "GUARDRAIL_INTERVENED":
    model_output = resp["outputs"][0]["text"]      # blocked message or masked text

The following table summarises the guardrail policies.

PolicyDetectsTypical use
Content filtersHate, insults, sexual, violence, misconductBlock harmful inputs and outputs
Prompt attack filterJailbreaks, prompt injection, prompt leakageProtect system instructions
Denied topicsNatural-language topic definitionsOut-of-scope or prohibited subjects
Word filtersExact words and profanityCompetitor names, banned terms
Sensitive information filtersPII types and regex patternsBlock or mask PII
Contextual grounding checkUngrounded or irrelevant responsesReduce RAG hallucinations
Automated Reasoning checksResponses that contradict formal policy rulesPolicy-accurate answers

The following diagram shows where the guardrail evaluates a request and its response.

Where a guardrail acts. It evaluates the user's input before the model and the model's output before the user. When a policy intervenes, the response is replaced with the configured blocked message and the stop reason shows a guardrail intervention. The policies include content and prompt attack filters, denied topics, word filters, sensitive information filters, contextual grounding and Automated Reasoning checks.
The trace output shows which policy intervened.
Scenario questions

Applying a guardrail

Exam skills 3.1.1 · 3.1.4

Choose how to apply Bedrock Guardrails in each architecture.

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

A banking assistant

A bank's assistant must refuse investment advice, never reveal full card numbers, block abusive language and not answer from outside its retrieved documents.

One guardrail covers all four: a denied topic for investment advice, a sensitive information filter masking credit card numbers in outputs, content filters for insults and hate on inputs and outputs, and a contextual grounding check with grounding and relevance thresholds. It is attached by version to the RetrieveAndGenerate calls.

Check yourself

Which guardrail policy masks email addresses in responses?

Show answer

The sensitive information filter, set to mask that PII type.

Exam Tips

Remember for the exam

  • Content filters have strengths per category for inputs and outputs.
  • Denied topics block subjects defined in natural language.
  • Sensitive information filters block or mask PII and regex matches.
  • Contextual grounding checks score grounding and relevance against thresholds.
  • ApplyGuardrail protects any model or text without invoking Bedrock models.