Skip to content

Commit 8c5f9c5

Browse files
committed
notebooks
1 parent c4b7b4b commit 8c5f9c5

27 files changed

+5613
-2768
lines changed

docs/examples/bug_free_python_code.ipynb

Lines changed: 59 additions & 152 deletions
Large diffs are not rendered by default.

docs/examples/check_for_pii.ipynb

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 1,
17+
"execution_count": 2,
1818
"metadata": {},
1919
"outputs": [
2020
{
2121
"name": "stdout",
2222
"output_type": "stream",
2323
"text": [
24-
"\n",
25-
"\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;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1.1\u001b[0m\n",
26-
"\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;49mpip install --upgrade pip\u001b[0m\n",
27-
"\n",
28-
"\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;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1.1\u001b[0m\n",
29-
"\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;49mpip install --upgrade pip\u001b[0m\n",
30-
"\u001b[38;5;2m✔ Download and installation successful\u001b[0m\n",
24+
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
25+
"sagemaker 2.232.2 requires numpy<2.0,>=1.9.0, but you have numpy 2.0.2 which is incompatible.\u001b[0m\u001b[31m\n",
26+
"\u001b[0m\u001b[38;5;2m✔ Download and installation successful\u001b[0m\n",
3127
"You can now load the package via spacy.load('en_core_web_lg')\n",
3228
"Installing hub:\u001b[35m/\u001b[0m\u001b[35m/guardrails/\u001b[0m\u001b[95mdetect_pii...\u001b[0m\n",
3329
"✅Successfully installed guardrails/detect_pii!\n",
@@ -46,7 +42,7 @@
4642
},
4743
{
4844
"cell_type": "code",
49-
"execution_count": 2,
45+
"execution_count": 1,
5046
"metadata": {},
5147
"outputs": [],
5248
"source": [
@@ -58,7 +54,7 @@
5854
},
5955
{
6056
"cell_type": "code",
61-
"execution_count": 3,
57+
"execution_count": 2,
6258
"metadata": {},
6359
"outputs": [],
6460
"source": [
@@ -72,14 +68,22 @@
7268
},
7369
{
7470
"cell_type": "code",
75-
"execution_count": 4,
71+
"execution_count": 3,
7672
"metadata": {},
7773
"outputs": [
74+
{
75+
"name": "stderr",
76+
"output_type": "stream",
77+
"text": [
78+
"/Users/dtam/dev/guardrails/guardrails/validator_service/__init__.py:85: UserWarning: Could not obtain an event loop. Falling back to synchronous validation.\n",
79+
" warnings.warn(\n"
80+
]
81+
},
7882
{
7983
"data": {
8084
"text/html": [
8185
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationOutcome</span><span style=\"font-weight: bold\">(</span>\n",
82-
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'11369602960'</span>,\n",
86+
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'14118728112'</span>,\n",
8387
" <span style=\"color: #808000; text-decoration-color: #808000\">raw_llm_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My email address is [email protected], and my phone number is 1234567890'</span>,\n",
8488
" <span style=\"color: #808000; text-decoration-color: #808000\">validated_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My email address is &lt;EMAIL_ADDRESS&gt;, and my phone number is &lt;PHONE_NUMBER&gt;'</span>,\n",
8589
" <span style=\"color: #808000; text-decoration-color: #808000\">reask</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
@@ -90,7 +94,7 @@
9094
],
9195
"text/plain": [
9296
"\u001b[1;35mValidationOutcome\u001b[0m\u001b[1m(\u001b[0m\n",
93-
" \u001b[33mcall_id\u001b[0m=\u001b[32m'11369602960'\u001b[0m,\n",
97+
" \u001b[33mcall_id\u001b[0m=\u001b[32m'14118728112'\u001b[0m,\n",
9498
" \u001b[33mraw_llm_output\u001b[0m=\u001b[32m'My email address is [email protected], and my phone number is 1234567890'\u001b[0m,\n",
9599
" \u001b[33mvalidated_output\u001b[0m=\u001b[32m'My email address is \u001b[0m\u001b[32m<\u001b[0m\u001b[32mEMAIL_ADDRESS\u001b[0m\u001b[32m>, and my phone number is <PHONE_NUMBER\u001b[0m\u001b[32m>\u001b[0m\u001b[32m'\u001b[0m,\n",
96100
" \u001b[33mreask\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
@@ -123,14 +127,22 @@
123127
},
124128
{
125129
"cell_type": "code",
126-
"execution_count": 5,
130+
"execution_count": 4,
127131
"metadata": {},
128132
"outputs": [
133+
{
134+
"name": "stderr",
135+
"output_type": "stream",
136+
"text": [
137+
"/Users/dtam/dev/guardrails/guardrails/validator_service/__init__.py:85: UserWarning: Could not obtain an event loop. Falling back to synchronous validation.\n",
138+
" warnings.warn(\n"
139+
]
140+
},
129141
{
130142
"data": {
131143
"text/html": [
132144
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationOutcome</span><span style=\"font-weight: bold\">(</span>\n",
133-
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'12272632448'</span>,\n",
145+
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'14120164704'</span>,\n",
134146
" <span style=\"color: #808000; text-decoration-color: #808000\">raw_llm_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My email address is [email protected], and my phone number is 1234567890'</span>,\n",
135147
" <span style=\"color: #808000; text-decoration-color: #808000\">validated_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My email address is &lt;EMAIL_ADDRESS&gt;, and my phone number is 1234567890'</span>,\n",
136148
" <span style=\"color: #808000; text-decoration-color: #808000\">reask</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
@@ -141,7 +153,7 @@
141153
],
142154
"text/plain": [
143155
"\u001b[1;35mValidationOutcome\u001b[0m\u001b[1m(\u001b[0m\n",
144-
" \u001b[33mcall_id\u001b[0m=\u001b[32m'12272632448'\u001b[0m,\n",
156+
" \u001b[33mcall_id\u001b[0m=\u001b[32m'14120164704'\u001b[0m,\n",
145157
" \u001b[33mraw_llm_output\u001b[0m=\u001b[32m'My email address is [email protected], and my phone number is 1234567890'\u001b[0m,\n",
146158
" \u001b[33mvalidated_output\u001b[0m=\u001b[32m'My email address is \u001b[0m\u001b[32m<\u001b[0m\u001b[32mEMAIL_ADDRESS\u001b[0m\u001b[32m>\u001b[0m\u001b[32m, and my phone number is 1234567890'\u001b[0m,\n",
147159
" \u001b[33mreask\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
@@ -175,7 +187,7 @@
175187
},
176188
{
177189
"cell_type": "code",
178-
"execution_count": 6,
190+
"execution_count": 5,
179191
"metadata": {},
180192
"outputs": [],
181193
"source": [
@@ -186,14 +198,22 @@
186198
},
187199
{
188200
"cell_type": "code",
189-
"execution_count": 7,
201+
"execution_count": 6,
190202
"metadata": {},
191203
"outputs": [
204+
{
205+
"name": "stderr",
206+
"output_type": "stream",
207+
"text": [
208+
"/Users/dtam/dev/guardrails/guardrails/validator_service/__init__.py:85: UserWarning: Could not obtain an event loop. Falling back to synchronous validation.\n",
209+
" warnings.warn(\n"
210+
]
211+
},
192212
{
193213
"data": {
194214
"text/html": [
195215
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationOutcome</span><span style=\"font-weight: bold\">(</span>\n",
196-
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'11371854608'</span>,\n",
216+
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'14120171344'</span>,\n",
197217
" <span style=\"color: #808000; text-decoration-color: #808000\">raw_llm_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My email address is [email protected], and my account number is 1234789012367654.'</span>,\n",
198218
" <span style=\"color: #808000; text-decoration-color: #808000\">validated_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My email address is [email protected], and my account number is &lt;US_BANK_NUMBER&gt;.'</span>,\n",
199219
" <span style=\"color: #808000; text-decoration-color: #808000\">reask</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
@@ -204,7 +224,7 @@
204224
],
205225
"text/plain": [
206226
"\u001b[1;35mValidationOutcome\u001b[0m\u001b[1m(\u001b[0m\n",
207-
" \u001b[33mcall_id\u001b[0m=\u001b[32m'11371854608'\u001b[0m,\n",
227+
" \u001b[33mcall_id\u001b[0m=\u001b[32m'14120171344'\u001b[0m,\n",
208228
" \u001b[33mraw_llm_output\u001b[0m=\u001b[32m'My email address is [email protected], and my account number is 1234789012367654.'\u001b[0m,\n",
209229
" \u001b[33mvalidated_output\u001b[0m=\u001b[32m'My email address is [email protected], and my account number is \u001b[0m\u001b[32m<\u001b[0m\u001b[32mUS_BANK_NUMBER\u001b[0m\u001b[32m>\u001b[0m\u001b[32m.'\u001b[0m,\n",
210230
" \u001b[33mreask\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
@@ -238,14 +258,22 @@
238258
},
239259
{
240260
"cell_type": "code",
241-
"execution_count": 8,
261+
"execution_count": 7,
242262
"metadata": {},
243263
"outputs": [
264+
{
265+
"name": "stderr",
266+
"output_type": "stream",
267+
"text": [
268+
"/Users/dtam/dev/guardrails/guardrails/validator_service/__init__.py:85: UserWarning: Could not obtain an event loop. Falling back to synchronous validation.\n",
269+
" warnings.warn(\n"
270+
]
271+
},
244272
{
245273
"data": {
246274
"text/html": [
247275
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ValidationOutcome</span><span style=\"font-weight: bold\">(</span>\n",
248-
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'11371849968'</span>,\n",
276+
" <span style=\"color: #808000; text-decoration-color: #808000\">call_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'14120169344'</span>,\n",
249277
" <span style=\"color: #808000; text-decoration-color: #808000\">raw_llm_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">\"My ITIN is 923756789 and my driver's license number is 87651239\"</span>,\n",
250278
" <span style=\"color: #808000; text-decoration-color: #808000\">validated_output</span>=<span style=\"color: #008000; text-decoration-color: #008000\">\"My ITIN is &lt;US_ITIN&gt; and my driver's license number is &lt;US_DRIVER_LICENSE&gt;\"</span>,\n",
251279
" <span style=\"color: #808000; text-decoration-color: #808000\">reask</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
@@ -256,7 +284,7 @@
256284
],
257285
"text/plain": [
258286
"\u001b[1;35mValidationOutcome\u001b[0m\u001b[1m(\u001b[0m\n",
259-
" \u001b[33mcall_id\u001b[0m=\u001b[32m'11371849968'\u001b[0m,\n",
287+
" \u001b[33mcall_id\u001b[0m=\u001b[32m'14120169344'\u001b[0m,\n",
260288
" \u001b[33mraw_llm_output\u001b[0m=\u001b[32m\"My\u001b[0m\u001b[32m ITIN is 923756789 and my driver's license number is 87651239\"\u001b[0m,\n",
261289
" \u001b[33mvalidated_output\u001b[0m=\u001b[32m\"My\u001b[0m\u001b[32m ITIN is \u001b[0m\u001b[32m<\u001b[0m\u001b[32mUS_ITIN\u001b[0m\u001b[32m> and my driver's license number is <US_DRIVER_LICENSE\u001b[0m\u001b[32m>\u001b[0m\u001b[32m\"\u001b[0m,\n",
262290
" \u001b[33mreask\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
@@ -292,7 +320,7 @@
292320
],
293321
"metadata": {
294322
"kernelspec": {
295-
"display_name": "guard-venv",
323+
"display_name": "litellm",
296324
"language": "python",
297325
"name": "python3"
298326
},
@@ -306,7 +334,7 @@
306334
"name": "python",
307335
"nbconvert_exporter": "python",
308336
"pygments_lexer": "ipython3",
309-
"version": "3.12.1"
337+
"version": "3.12.3"
310338
}
311339
},
312340
"nbformat": 4,

0 commit comments

Comments
 (0)