AWS Certified Developer – Associate
Amazon Bedrock Guardrails policies and filters for DVA-C03
The Amazon Bedrock User Guide describes a guardrail as a set of filters that check prompts and model responses: content filters, denied topics, word filters, sensitive information filters and contextual grounding checks. You attach a guardrail version to an inference call, or call ApplyGuardrail to check text without invoking a model.
What does each guardrail policy do?
Content filters detect harmful text in the categories Hate, Insults, Sexual, Violence, Misconduct and Prompt Attack, with a strength you set per category. Misconduct covers seeking or giving information about criminal activity or defrauding a person or organization.
Denied topics block a subject. Each topic has a name, a definition of up to 200 characters and up to five sample phrases, and a guardrail can hold up to 30 topics. The definition describes the subject. It must not be an instruction such as "Block all content about cryptocurrency", and topics should not be used to catch a single word or a person's name.
Word filters block custom words and phrases with case-insensitive whole-word matching, plus a ready-made profanity list. Sensitive information filters detect built-in PII types such as NAME and EMAIL and custom regex patterns. Block rejects the whole content. Mask replaces each match with its type, for example {NAME}.
Contextual grounding checks flag or block a response that is not grounded in the supplied source or is not relevant to the user's query, which suits retrieval-augmented generation.
Prompt attacks and input tags
The prompt attack filter covers jailbreaks, prompt injection and, in the Standard tier only, prompt leakage. A user's injection attempt can look like a developer's system prompt, so the guardrail needs to know which part of the prompt is user input.
With InvokeModel and InvokeModelWithResponseStream you wrap the user input in guardrail input tags. Without tags, prompt attacks are not filtered for those operations. With the Converse API the guardContent block does the same job.
Guardrail filters evaluate text. In tool use they do not evaluate tool results, tool definitions or the tool call arguments the model generates.
How is a guardrail applied?
For inference, pass the guardrail ID and version. In Converse and ConverseStream this is guardrailConfig with guardrailIdentifier, guardrailVersion and an optional trace. ApplyGuardrail evaluates any text with no model call. Set source to INPUT for user content and OUTPUT for model output. In a RAG application it can check the question before retrieval runs.
Streaming has two modes. The default synchronous mode buffers chunks and scans them before they are sent, which adds latency. Setting streamProcessingMode to ASYNCHRONOUS sends chunks at once and scans in the background, so a chunk can reach the user before the scan finishes, and masking of sensitive information is not supported.
A new guardrail has a working draft. A version is a snapshot that you create for production. Versions have no ARN of their own, so IAM policies restrict a version with the bedrock:GuardrailIdentifier condition key.
Filtering AI model inputs and outputs sits in Task 2.3 of the exam guide, a task that AWS lists as new in DVA-C03.
Where the exam catches people
- Believing a denied topic definition should be an instruction to the guardrail: actually it must describe the subject and its subtopics.
- Believing a denied topic is the way to block one person's or competitor's name: actually word filters or sensitive information filters handle words and entities.
- Believing
ApplyGuardrailruns the prompt through a model: actually it only evaluates the text against the guardrail. - Believing asynchronous streaming scans every chunk before the user sees it: actually only the default synchronous mode buffers and scans first.
- Believing the prompt attack filter checks untagged
InvokeModelprompts: actually user input must be wrapped in guardrail input tags for those operations.
Written from these sources
- Detect and filter harmful content by using Amazon Bedrock Guardrails
- Block harmful words and conversations with content filters
- Block denied topics to help remove harmful content
- Remove PII from conversations by using sensitive information filters
- Detect prompt attacks with Amazon Bedrock Guardrails
- Use the ApplyGuardrail API in your application
- Include a guardrail with the Converse API
- Configure streaming response behavior to filter content
- Deploy your guardrail
- Comparison of DVA-C02 and DVA-C03 (exam guide)