|
22 | 22 | }, |
23 | 23 | { |
24 | 24 | "cell_type": "code", |
25 | | - "execution_count": 10, |
| 25 | + "execution_count": null, |
26 | 26 | "id": "716c8924", |
27 | 27 | "metadata": {}, |
28 | | - "outputs": [ |
29 | | - { |
30 | | - "name": "stdout", |
31 | | - "output_type": "stream", |
32 | | - "text": [ |
33 | | - "Looking in indexes: https://pypi.org/simple, https://plugin.us-east-1.prod.workshops.aws\n", |
34 | | - "Collecting boto3\n", |
35 | | - " Using cached boto3-1.41.0-py3-none-any.whl.metadata (6.8 kB)\n", |
36 | | - "Collecting botocore<1.42.0,>=1.41.0 (from boto3)\n", |
37 | | - " Using cached botocore-1.41.0-py3-none-any.whl.metadata (5.9 kB)\n", |
38 | | - "Collecting jmespath<2.0.0,>=0.7.1 (from boto3)\n", |
39 | | - " Using cached jmespath-1.0.1-py3-none-any.whl.metadata (7.6 kB)\n", |
40 | | - "Collecting s3transfer<0.15.0,>=0.14.0 (from boto3)\n", |
41 | | - " Using cached s3transfer-0.14.0-py3-none-any.whl.metadata (1.7 kB)\n", |
42 | | - "Collecting python-dateutil<3.0.0,>=2.1 (from botocore<1.42.0,>=1.41.0->boto3)\n", |
43 | | - " Using cached python_dateutil-2.9.0.post0-py2.py3-none-any.whl.metadata (8.4 kB)\n", |
44 | | - "Collecting urllib3!=2.2.0,<3,>=1.25.4 (from botocore<1.42.0,>=1.41.0->boto3)\n", |
45 | | - " Using cached urllib3-2.5.0-py3-none-any.whl.metadata (6.5 kB)\n", |
46 | | - "Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore<1.42.0,>=1.41.0->boto3)\n", |
47 | | - " Using cached six-1.17.0-py2.py3-none-any.whl.metadata (1.7 kB)\n", |
48 | | - "Using cached boto3-1.41.0-py3-none-any.whl (139 kB)\n", |
49 | | - "Using cached botocore-1.41.0-py3-none-any.whl (14.2 MB)\n", |
50 | | - "Using cached jmespath-1.0.1-py3-none-any.whl (20 kB)\n", |
51 | | - "Using cached python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)\n", |
52 | | - "Using cached s3transfer-0.14.0-py3-none-any.whl (85 kB)\n", |
53 | | - "Using cached urllib3-2.5.0-py3-none-any.whl (129 kB)\n", |
54 | | - "Using cached six-1.17.0-py2.py3-none-any.whl (11 kB)\n", |
55 | | - "Installing collected packages: urllib3, six, jmespath, python-dateutil, botocore, s3transfer, boto3\n", |
56 | | - "\u001b[2K Attempting uninstall: urllib3\n", |
57 | | - "\u001b[2K Found existing installation: urllib3 2.5.0\n", |
58 | | - "\u001b[2K Uninstalling urllib3-2.5.0:\n", |
59 | | - "\u001b[2K Successfully uninstalled urllib3-2.5.0\n", |
60 | | - "\u001b[2K Attempting uninstall: six━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0/7\u001b[0m [urllib3]\n", |
61 | | - "\u001b[2K Found existing installation: six 1.17.0━\u001b[0m \u001b[32m0/7\u001b[0m [urllib3]\n", |
62 | | - "\u001b[2K Uninstalling six-1.17.0:━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0/7\u001b[0m [urllib3]\n", |
63 | | - "\u001b[2K Successfully uninstalled six-1.17.0━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1/7\u001b[0m [six]\n", |
64 | | - "\u001b[2K Attempting uninstall: jmespath━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1/7\u001b[0m [six]\n", |
65 | | - "\u001b[2K Found existing installation: jmespath 1.0.1━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1/7\u001b[0m [six]\n", |
66 | | - "\u001b[2K Uninstalling jmespath-1.0.1:━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1/7\u001b[0m [six]\n", |
67 | | - "\u001b[2K Successfully uninstalled jmespath-1.0.1━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1/7\u001b[0m [six]\n", |
68 | | - "\u001b[2K Attempting uninstall: python-dateutil━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2/7\u001b[0m [jmespath]\n", |
69 | | - "\u001b[2K Found existing installation: python-dateutil 2.9.0.post0━━\u001b[0m \u001b[32m2/7\u001b[0m [jmespath]\n", |
70 | | - "\u001b[2K Uninstalling python-dateutil-2.9.0.post0:━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2/7\u001b[0m [jmespath]\n", |
71 | | - "\u001b[2K Successfully uninstalled python-dateutil-2.9.0.post0━━━━\u001b[0m \u001b[32m2/7\u001b[0m [jmespath]\n", |
72 | | - "\u001b[2K Attempting uninstall: botocore0m━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2/7\u001b[0m [jmespath]\n", |
73 | | - "\u001b[2K Found existing installation: botocore 1.41.0━━━━━━━━━━━━━━\u001b[0m \u001b[32m2/7\u001b[0m [jmespath]\n", |
74 | | - "\u001b[2K Uninstalling botocore-1.41.0:m━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2/7\u001b[0m [jmespath]\n", |
75 | | - "\u001b[2K Successfully uninstalled botocore-1.41.090m━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4/7\u001b[0m [botocore]\n", |
76 | | - "\u001b[2K Attempting uninstall: s3transfer\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4/7\u001b[0m [botocore]\n", |
77 | | - "\u001b[2K Found existing installation: s3transfer 0.14.0━━━━━━━━━━━━\u001b[0m \u001b[32m4/7\u001b[0m [botocore]\n", |
78 | | - "\u001b[2K Uninstalling s3transfer-0.14.0:╸\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4/7\u001b[0m [botocore]\n", |
79 | | - "\u001b[2K Successfully uninstalled s3transfer-0.14.0━━━━━━━━━━━━━━\u001b[0m \u001b[32m4/7\u001b[0m [botocore]\n", |
80 | | - "\u001b[2K Attempting uninstall: boto3━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━\u001b[0m \u001b[32m5/7\u001b[0m [s3transfer]\n", |
81 | | - "\u001b[2K Found existing installation: boto3 1.41.0m\u001b[90m━━━━━━━━━━━\u001b[0m \u001b[32m5/7\u001b[0m [s3transfer]\n", |
82 | | - "\u001b[2K Uninstalling boto3-1.41.0:━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━\u001b[0m \u001b[32m5/7\u001b[0m [s3transfer]\n", |
83 | | - "\u001b[2K Successfully uninstalled boto3-1.41.0[0m\u001b[90m━━━━━━━━━━━\u001b[0m \u001b[32m5/7\u001b[0m [s3transfer]\n", |
84 | | - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7/7\u001b[0m [boto3]32m6/7\u001b[0m [boto3]]\n", |
85 | | - "\u001b[1A\u001b[2KSuccessfully installed boto3-1.41.0 botocore-1.41.0 jmespath-1.0.1 python-dateutil-2.9.0.post0 s3transfer-0.14.0 six-1.17.0 urllib3-2.5.0\n", |
86 | | - "\n", |
87 | | - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m25.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.3\u001b[0m\n", |
88 | | - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip3 install --upgrade pip\u001b[0m\n" |
89 | | - ] |
90 | | - } |
91 | | - ], |
| 28 | + "outputs": [], |
92 | 29 | "source": [ |
93 | 30 | "#Start by installing the dependencies to ensure we have a recent version\n", |
94 | | - "!pip install --upgrade --force-reinstall boto3\n", |
| 31 | + "!pip install --upgrade boto3\n", |
95 | 32 | "import boto3\n", |
96 | 33 | "import json" |
97 | 34 | ] |
98 | 35 | }, |
99 | 36 | { |
100 | 37 | "cell_type": "code", |
101 | | - "execution_count": 9, |
| 38 | + "execution_count": null, |
102 | 39 | "id": "2ba9275e", |
103 | 40 | "metadata": {}, |
104 | 41 | "outputs": [], |
|
133 | 70 | }, |
134 | 71 | { |
135 | 72 | "cell_type": "code", |
136 | | - "execution_count": 5, |
| 73 | + "execution_count": null, |
137 | 74 | "id": "13c291fc", |
138 | 75 | "metadata": {}, |
139 | | - "outputs": [ |
140 | | - { |
141 | | - "name": "stdout", |
142 | | - "output_type": "stream", |
143 | | - "text": [ |
144 | | - "{'ResponseMetadata': {'RequestId': '8dc78e1b-0727-409b-99b2-171a1df08146', 'HTTPStatusCode': 202, 'HTTPHeaders': {'date': 'Thu, 20 Nov 2025 02:18:57 GMT', 'content-type': 'application/json', 'content-length': '172', 'connection': 'keep-alive', 'x-amzn-requestid': '8dc78e1b-0727-409b-99b2-171a1df08146'}, 'RetryAttempts': 0}, 'guardrailId': '0v2ve519giw9', 'guardrailArn': 'arn:aws:bedrock:us-east-1:686642339053:guardrail/0v2ve519giw9', 'version': 'DRAFT', 'createdAt': datetime.datetime(2025, 11, 20, 2, 18, 57, 659905, tzinfo=tzutc())}\n" |
145 | | - ] |
146 | | - } |
147 | | - ], |
| 76 | + "outputs": [], |
148 | 77 | "source": [ |
149 | 78 | "create_response = client.create_guardrail(\n", |
150 | 79 | " name='code-modality-guardrail',\n", |
|
231 | 160 | }, |
232 | 161 | { |
233 | 162 | "cell_type": "code", |
234 | | - "execution_count": 11, |
| 163 | + "execution_count": null, |
235 | 164 | "id": "ab0a32d5", |
236 | 165 | "metadata": {}, |
237 | 166 | "outputs": [], |
|
242 | 171 | }, |
243 | 172 | { |
244 | 173 | "cell_type": "code", |
245 | | - "execution_count": 24, |
| 174 | + "execution_count": null, |
246 | 175 | "id": "cc843d1b", |
247 | 176 | "metadata": {}, |
248 | | - "outputs": [ |
249 | | - { |
250 | | - "name": "stdout", |
251 | | - "output_type": "stream", |
252 | | - "text": [ |
253 | | - "API Response Elements:\n", |
254 | | - "Response of Guardrail: GUARDRAIL_INTERVENED\n", |
255 | | - "\n", |
256 | | - "Content Policy Assessment:\n", |
257 | | - " Type: PROMPT_ATTACK | Confidence: HIGH | Action: BLOCKED\n", |
258 | | - " Type: MISCONDUCT | Confidence: LOW | Action: BLOCKED\n" |
259 | | - ] |
260 | | - } |
261 | | - ], |
| 177 | + "outputs": [], |
262 | 178 | "source": [ |
263 | 179 | "# Example of Input Prompt with harmful intent\n", |
264 | 180 | "# Notice the output \n", |
|
308 | 224 | }, |
309 | 225 | { |
310 | 226 | "cell_type": "code", |
311 | | - "execution_count": 18, |
| 227 | + "execution_count": null, |
312 | 228 | "id": "e90191c5", |
313 | 229 | "metadata": {}, |
314 | | - "outputs": [ |
315 | | - { |
316 | | - "name": "stdout", |
317 | | - "output_type": "stream", |
318 | | - "text": [ |
319 | | - "API Response Elements:\n", |
320 | | - "Response of Guardrail: GUARDRAIL_INTERVENED\n", |
321 | | - "\n", |
322 | | - "Content Policy Assessment:\n", |
323 | | - " Type: MISCONDUCT | Confidence: HIGH | Action: BLOCKED\n", |
324 | | - "\n", |
325 | | - "Sensitive Information Policy Assessment:\n", |
326 | | - " Found: US_SOCIAL_SECURITY_NUMBER | Match: '123-45-6789' | Action: BLOCKED\n" |
327 | | - ] |
328 | | - } |
329 | | - ], |
| 230 | + "outputs": [], |
330 | 231 | "source": [ |
331 | 232 | "# Example of Input Prompt with harmful intent\n", |
332 | 233 | "# Notice the output \n", |
|
387 | 288 | "execution_count": null, |
388 | 289 | "id": "d0eb65b1", |
389 | 290 | "metadata": {}, |
390 | | - "outputs": [ |
391 | | - { |
392 | | - "name": "stdout", |
393 | | - "output_type": "stream", |
394 | | - "text": [ |
395 | | - "API Response Elements:\n", |
396 | | - "Response of Guardrail: GUARDRAIL_INTERVENED\n", |
397 | | - "\n", |
398 | | - "Content Policy Assessment:\n", |
399 | | - " Type: HATE | Confidence: HIGH | Action: BLOCKED\n" |
400 | | - ] |
401 | | - } |
402 | | - ], |
| 291 | + "outputs": [], |
403 | 292 | "source": [ |
404 | 293 | "# Example of Input Prompt with harmful intent\n", |
405 | 294 | "# Notice the output \n", |
|
439 | 328 | }, |
440 | 329 | { |
441 | 330 | "cell_type": "code", |
442 | | - "execution_count": 23, |
| 331 | + "execution_count": null, |
443 | 332 | "id": "a9ceddb1", |
444 | 333 | "metadata": {}, |
445 | | - "outputs": [ |
446 | | - { |
447 | | - "name": "stdout", |
448 | | - "output_type": "stream", |
449 | | - "text": [ |
450 | | - "API Response Elements:\n", |
451 | | - "Response of Guardrail: GUARDRAIL_INTERVENED\n", |
452 | | - "\n", |
453 | | - "Topic Policy Assessment:\n", |
454 | | - " Topic Name: N/A | Action: BLOCKED\n" |
455 | | - ] |
456 | | - } |
457 | | - ], |
| 334 | + "outputs": [], |
458 | 335 | "source": [ |
459 | 336 | "# Example of Input Prompt with harmful intent\n", |
460 | 337 | "# Notice the output \n", |
|
0 commit comments