AWS Certified Generative AI Developer – Professional
Guardrails for Amazon Bedrock: which filter to use (AIP-C01)
A guardrail is a set of policies applied to prompts and model responses. Content filters catch harmful categories by strength, denied topics block subjects you define, word filters block exact words, sensitive information filters block or mask PII and regex matches, and grounding and Automated Reasoning checks catch inaccurate responses. Each filter can act differently on input and output.
The policies
Content filters detect Hate, Insults, Sexual, Violence, Misconduct and Prompt Attack in text or images. You set a strength of NONE, LOW, MEDIUM or HIGH separately for prompts (inputStrength) and responses (outputStrength).
Denied topics block subjects that you describe, in user queries or model responses.
Word filters block exact words and phrases with case-insensitive whole-word matching. Add your own words, such as competitor and product names, or turn on the ready-made profanity filter, which AWS keeps updated.
Sensitive information filters block or mask PII such as names, email addresses and SSNs, and can use custom regex patterns for formats like booking IDs. Masking replaces the value with its type, for example {NAME} or {EMAIL}, and the rest of the text is still returned.
Contextual grounding checks flag responses that are not grounded in the source or not relevant to the query. Automated Reasoning checks validate responses against logical rules.
Input action vs output action
Each content filter has an inputAction and an outputAction. BLOCK replaces the content with the blocked message. NONE takes no action but returns what was detected in the trace response.
Example: a telehealth bot blocks patients who describe injuries. Set the Violence filter's inputAction to NONE and keep outputAction at BLOCK, create a new guardrail version, and enable trace so the application can log what the filter saw on each prompt. inputEnabled false would instead skip the evaluation, so nothing would be recorded.
Drafts and versions
A new guardrail has a working draft that you can change and test in the console test window. When it behaves as you want, create a version and reference the guardrail ID and version in inference calls or the ApplyGuardrail API.
Where the exam catches people
- Believing BLOCK on NAME and EMAIL keeps the summary: BLOCK returns the blocked message. ANONYMIZE masks the values and returns the rest.
- Believing a custom word list is the way to catch an ID format such as POL- plus eight digits: a regex in the sensitive information filter matches the pattern.
- Believing you must maintain your own list of profane words: the word filter has a profanity option that AWS keeps updated.
- Believing inputEnabled false records detections: it skips the evaluation. inputAction NONE evaluates, does not block, and returns detections in the trace.
- Believing the Misconduct content filter blocks competitor names: exact names belong in a custom word filter.
Written from Amazon Web Services's documentation
- Detect and filter harmful content by using Amazon Bedrock Guardrails
- Block harmful words and conversations with content filters
- Remove PII from conversations by using sensitive information filters
- Remove a specific list of words and phrases from conversations with word filters
- GuardrailContentFilterConfig (Amazon Bedrock API reference)