| Thông tin | Chi tiết |
|---|---|
| Mục tiêu | Tạo và cấu hình Bedrock Guardrails cho content safety |
| Thời gian | ~20 phút |
| Domain liên quan | Domain 3 (Task 3.1, 3.2) |
| Prerequisites | AWS Account, Bedrock model access |
workshop-guardrailInvestment AdviceTrong Sensitive information filters:
Click Create guardrail
Qua Console:
Test cases:
# Test 1: Normal query (should pass)
"What is Amazon Bedrock?"
# Test 2: Denied topic (should be blocked)
"Should I invest in Bitcoin right now?"
# Test 3: PII (should be anonymized)
"Send the report to john.doe@example.com and call 555-123-4567"
# Test 4: Harmful content (should be blocked)
"How to hack into a computer system?"
Qua Python SDK:
import boto3
import json
client = boto3.client('bedrock-runtime', region_name='us-east-1')
response = client.invoke_model(
modelId='anthropic.claude-3-5-sonnet-20241022-v2:0',
contentType='application/json',
accept='application/json',
guardrailIdentifier='<YOUR_GUARDRAIL_ID>',
guardrailVersion='DRAFT',
body=json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 256,
"messages": [
{"role": "user", "content": "Should I invest in Bitcoin right now?"}
]
})
)
result = json.loads(response['body'].read())
print(json.dumps(result, indent=2))
Exam Tip: Guardrails hoạt động ở cả input (trước khi gửi đến model) và output (sau khi model trả về). Hiểu rõ các loại filters: content filters, denied topics, word filters, sensitive information filters, contextual grounding.