Task 3.1: Input & Output Safety Controls

Task 3.1: Triển khai input và output safety controls

Skill 3.1.1: Content safety cho inputs

Kiến thức cần nắm:

  • Amazon Bedrock Guardrails — Content filtering cho harmful inputs
  • Step Functions và Lambda cho custom moderation workflows
  • Real-time validation mechanisms

Giải thích chi tiết:

Amazon Bedrock Guardrails cung cấp nhiều lớp bảo vệ:

Filter TypeMô tảVí dụ
Content filtersLọc nội dung harmful (hate, violence, sexual)Block prompts chứa nội dung bạo lực
Denied topicsChặn topics cụ thểKhông cho phép hỏi về financial advice
Word filtersBlock từ/cụm từ cụ thểChặn profanity, competitor names
PII filtersDetect và redact PIIMask email, phone numbers
Contextual groundingKiểm tra factual accuracyVerify response dựa trên source documents

Cấu hình Guardrails:

import boto3

client = boto3.client('bedrock')

response = client.create_guardrail(
    name='content-safety-guardrail',
    description='Filter harmful content',
    contentPolicyConfig={
        'filtersConfig': [
            {
                'type': 'SEXUAL',
                'inputStrength': 'HIGH',
                'outputStrength': 'HIGH'
            },
            {
                'type': 'VIOLENCE',
                'inputStrength': 'HIGH',
                'outputStrength': 'HIGH'
            },
            {
                'type': 'HATE',
                'inputStrength': 'HIGH',
                'outputStrength': 'HIGH'
            }
        ]
    }
)

Skill 3.1.2: Content safety cho outputs

Kiến thức cần nắm:

  • Bedrock Guardrails cho response filtering
  • FM evaluations cho content moderation và toxicity detection
  • Text-to-SQL transformations cho deterministic results

Giải thích chi tiết:

Output Safety Layers:

  1. Guardrails output filters — Tự động scan và filter responses
  2. Post-processing Lambda — Custom validation logic
  3. Structured outputs — JSON Schema enforcement giảm free-form hallucination
  4. Text-to-SQL — Chuyển natural language thành SQL queries cho deterministic results

Skill 3.1.3: Giảm hallucination

Kiến thức cần nắm:

  • Amazon Bedrock Knowledge Bases cho grounding responses (fact checking)
  • Confidence scoring và semantic similarity search
  • JSON Schema cho structured outputs

Exam Tip: Khi gặp câu hỏi về giảm hallucination, câu trả lời thường liên quan đến RAG/Knowledge Bases (grounding), Guardrails, hoặc structured outputs. Đây là pattern rất phổ biến trong đề thi.

Strategies giảm hallucination:

StrategyImplementationHiệu quả
RAG/GroundingKnowledge BasesCao — cung cấp factual context
Structured outputsJSON SchemaTrung bình — giới hạn format
Contextual groundingGuardrailsCao — verify against sources
Temperature thấpModel parametersTrung bình — giảm creativity
Chain-of-thoughtPrompt engineeringTrung bình — improve reasoning

Skill 3.1.4: Defense-in-depth safety

Kiến thức cần nắm:

  • Amazon Comprehend cho pre-processing filters
  • Amazon Bedrock cho model-based guardrails
  • Lambda cho post-processing validation
  • API Gateway cho API response filtering

Defense-in-depth architecture:

User Input
    ↓
[Layer 1: API Gateway] — Rate limiting, WAF rules
    ↓
[Layer 2: Pre-processing] — Comprehend PII detection, input sanitization
    ↓
[Layer 3: Guardrails] — Bedrock Guardrails (content filters, denied topics)
    ↓
[Layer 4: FM Invocation] — Model generates response
    ↓
[Layer 5: Output Guardrails] — Response filtering, PII redaction
    ↓
[Layer 6: Post-processing] — Lambda custom validation
    ↓
Safe Response to User

Skill 3.1.5: Advanced threat detection

Kiến thức cần nắm:

  • Prompt injection detection mechanisms
  • Jailbreak detection
  • Input sanitization và content filters
  • Safety classifiers
  • Automated adversarial testing workflows

Giải thích chi tiết:

Prompt Injection Types:

TypeMô tảMitigation
Direct injectionUser trực tiếp inject malicious instructionsInput validation, Guardrails
Indirect injectionMalicious content trong retrieved documentsSource validation, output filtering
JailbreakBypass safety controls qua creative promptingSafety classifiers, Guardrails

Mitigation strategies:

  • Guardrails với custom denied topics
  • Input sanitization trước khi gửi tới FM
  • Separate system prompts từ user inputs
  • Monitor và log tất cả interactions

Tài liệu tham khảo