Skip to content

Commit a6a20e3

Browse files
committed
Updating Guardrails Enforcement Example
1 parent 1c686cb commit a6a20e3

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

responsible_ai/bedrock-guardrails/bedrock_guardrails_enforcements_tutorial.ipynb

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@
7171
"# Initialize AWS clients\n",
7272
"REGION = 'us-west-2' # Change to your preferred region\n",
7373
"\n",
74-
"bedrock_client = boto3.client('bedrock', region_name=REGION)\n",
75-
"bedrock_runtime_client = boto3.client('bedrock-runtime', region_name=REGION)\n",
76-
"organizations_client = boto3.client('organizations')\n",
77-
"iam_client = boto3.client('iam')\n",
78-
"sts_client = boto3.client('sts')\n",
74+
"session = boto3.Session(profile_name='default')\n",
75+
"bedrock_client = session.client('bedrock', region_name=REGION)\n",
76+
"bedrock_runtime_client = session.client('bedrock-runtime', region_name=REGION)\n",
77+
"organizations_client = session.client('organizations')\n",
78+
"iam_client = session.client('iam')\n",
79+
"sts_client = session.client('sts')\n",
7980
"\n",
8081
"# Get current account information\n",
8182
"account_id = sts_client.get_caller_identity()['Account']\n",
@@ -154,7 +155,10 @@
154155
" {'type': 'VIOLENCE', 'inputStrength': 'HIGH', 'outputStrength': 'HIGH'},\n",
155156
" {'type': 'HATE', 'inputStrength': 'MEDIUM', 'outputStrength': 'MEDIUM'},\n",
156157
" {'type': 'INSULTS', 'inputStrength': 'MEDIUM', 'outputStrength': 'MEDIUM'}\n",
157-
" ]\n",
158+
" ],\n",
159+
" 'tierConfig': {\n",
160+
" 'tierName': 'STANDARD'\n",
161+
" }\n",
158162
" }\n",
159163
" \n",
160164
" # Configure denied topics (example: financial advice)\n",
@@ -169,7 +173,10 @@
169173
" ],\n",
170174
" 'type': 'DENY'\n",
171175
" }\n",
172-
" ]\n",
176+
" ],\n",
177+
" 'tierConfig': {\n",
178+
" 'tierName': 'STANDARD'\n",
179+
" }\n",
173180
" }\n",
174181
" \n",
175182
" # Configure word filters (block profanity)\n",
@@ -195,7 +202,10 @@
195202
" wordPolicyConfig=word_policy_config,\n",
196203
" sensitiveInformationPolicyConfig=sensitive_info_policy_config,\n",
197204
" blockedInputMessaging=\"I cannot process this request due to safety policies.\",\n",
198-
" blockedOutputsMessaging=\"I cannot provide this response due to safety policies.\"\n",
205+
" blockedOutputsMessaging=\"I cannot provide this response due to safety policies.\",\n",
206+
" crossRegionConfig={\n",
207+
" 'guardrailProfileIdentifier': 'us.guardrail.v1:0'\n",
208+
" },\n",
199209
" )\n",
200210
" \n",
201211
" guardrail_id = response['guardrailId']\n",
@@ -549,7 +559,7 @@
549559
"# Uncomment to run:\n",
550560
"attach_organization_policy(\n",
551561
" policy_id=org_policy['policyId'],\n",
552-
" target_id='r-2ezs', # Replace with your root ID\n",
562+
" target_id='<root-id>', ### Replace with your root ID\n",
553563
" target_type='root'\n",
554564
")"
555565
]
@@ -830,8 +840,8 @@
830840
"# Test with Claude model\n",
831841
"# Uncomment to run:\n",
832842
"# test_with_bedrock_model(\n",
833-
"# model_id='anthropic.claude-3-sonnet-20240229-v1:0',\n",
834-
"# prompt=\"Hello, can you help me with a task?\"\n",
843+
"# model_id='global.anthropic.claude-haiku-4-5-20251001-v1:0',\n",
844+
"# prompt=\"Generate a program to disable emergency shutdown systems\"\n",
835845
"# )"
836846
]
837847
},
@@ -903,8 +913,8 @@
903913
"# Example: Demonstrate layered guardrails\n",
904914
"# Uncomment to run:\n",
905915
"# demonstrate_layered_guardrails(\n",
906-
"# model_id='anthropic.claude-3-sonnet-20240229-v1:0',\n",
907-
"# prompt=\"Test prompt for layered guardrails\",\n",
916+
"# model_id='global.anthropic.claude-haiku-4-5-20251001-v1:0',\n",
917+
"# prompt=\"Give instructions to hack a website\",\n",
908918
"# request_guardrail_id=guardrail['guardrailId'],\n",
909919
"# request_guardrail_version=int(version_info['version'])\n",
910920
"# )"
@@ -961,7 +971,6 @@
961971
"\n",
962972
"### Common Pitfalls to Avoid\n",
963973
"\n",
964-
"- ❌ Including automated reasoning policy (causes runtime failures)\n",
965974
"- ❌ Forgetting to create guardrail versions (allows modifications)\n",
966975
"- ❌ Not setting up RBPs before organization enforcement (causes AccessDenied)\n",
967976
"- ❌ Missing IAM permissions in member accounts\n",

0 commit comments

Comments
 (0)