๐Ÿ›ก๏ธ 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

  1. Create Guardrail โ€“ Define a name and blocked message (e.g., โ€œSorry, the model cannot answer this question.โ€).
  2. 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.
  3. Test the Guardrail โ€“ Run a prompt and see if it blocks or masks correctly.
  4. Apply to Models โ€“ You can assign guardrails to any supported Foundation Model (e.g., Anthropic, Sonnet).
  5. 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