AWS Certified AI Practitioner(9) - Guardrails
๐ก๏ธ Amazon Bedrock โ Guardrails
๐ What Are Guardrails?
Guardrails in Amazon Bedrock are a way to control and filter interactions between users and Foundation Models (FMs).
They help ensure that AI responses are safe, reliable, and compliant with your requirements.
๐ Key Features of Guardrails
- Filter harmful content: Block hate speech, insults, sexual, violent, or misconduct content.
- Block specific topics: Deny responses related to sensitive or restricted subjects (e.g., recipes, medical advice).
- Protect privacy: Automatically detect and remove PII (Personally Identifiable Information) such as emails, phone numbers, or addresses.
- Reduce hallucinations: Add contextual grounding so the model gives factual and relevant answers.
- Custom word filters: Upload your own list of banned words or phrases.
- Multiple guardrails: Apply different guardrails for different use cases and stack them together.
- Monitoring & analysis: Track user inputs that violate guardrails to improve system safety.
โ๏ธ Example Use Cases
1. Block Restricted Topics
- Scenario: You donโt want your model to answer food recipe requests.
- User prompt: โSuggest me something to cook tonight.โ
- Guardrail response: โSorry, this is a restricted topic.โ
2. Mask PII (Privacy Protection)
- User prompt: โDraft an email to stephane@example.com and cc john@example.com.โ
- Guardrail action: Automatically masks emails โ
To: [PII Removed], CC: [PII Removed]
This ensures user privacy is protected.
๐ ๏ธ How to Configure a Guardrail
- Create Guardrail โ Define a name and blocked message (e.g., โSorry, the model cannot answer this question.โ).
- Set Filters
- Content filters: hate, insults, sexual, violence, misconduct.
- Denied topics: e.g., recipes, sensitive domains.
- Word filters: add custom banned terms.
- PII filters: mask emails, phone numbers, etc.
- Regex filters: remove any pattern-based info (like credit card numbers).
- Grounding: reduce hallucinations by checking answer relevance.
- Test the Guardrail โ Run a prompt and see if it blocks or masks correctly.
- Apply to Models โ You can assign guardrails to any supported Foundation Model (e.g., Anthropic, Sonnet).
- Stack Multiple Guardrails โ Combine several guardrails for stricter control.
โ Why Use Guardrails?
- Ensure responsible AI usage.
- Protect your business from legal, ethical, and compliance risks.
- Enhance user trust by safeguarding privacy and filtering harmful content.
- Maintain high-quality, relevant, and safe outputs from AI models.
๐ In summary:
Amazon Bedrock Guardrails are like safety rules for your AI, helping you filter content, protect privacy, and keep AI responses accurate and responsible.
๐ Amazon Bedrock Guardrails Summary Table
Category | Explanation | Example |
---|---|---|
Purpose | Control and filter interactions between users and Foundation Models (FMs) | Prevent AI from producing unsafe or irrelevant outputs |
Content Filtering | Blocks harmful categories (hate, violence, sexual, misconduct, insults) | User asks: โWrite a violent story.โ โ Response blocked |
Denied Topics | Restrict responses on specific topics you define | Recipes, medical advice, legal guidance |
PII Protection | Detect and remove Personally Identifiable Information | Emails, phone numbers, credit cards masked |
Word Filters | Custom banned words/phrases can be uploaded | Block profanity or sensitive business terms |
Regex Patterns | Remove data that matches a specific structure | Mask credit card numbers: 1234-5678-9012-3456 |
Grounding (Reduce Hallucinations) | Ensures responses are relevant and fact-based | Prevents AI from โmaking upโ answers |
Multiple Guardrails | You can stack several guardrails together for stricter control | One for PII + one for harmful content |
Monitoring | Logs violations to analyze and improve system safety | Track how often guardrails are triggered |
Blocked Response Message | Customizable message shown when prompt is blocked | โSorry, this question cannot be answered.โ |
โ Key Benefits
- Responsible AI โ Prevents harmful or irrelevant responses
- Enhanced Privacy โ Removes PII and sensitive data
- Trust & Compliance โ Keeps outputs aligned with regulations and ethics
- Flexibility โ You can tailor guardrails to your business needs
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.