Skip to content

Commit 4a1fd14

Browse files
committed
add cell to top of notebooks
1 parent fe698a4 commit 4a1fd14

17 files changed

+175
-150
lines changed

docs/examples/bug_free_python_code.ipynb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://reflex/valid_python"
10+
]
11+
},
312
{
413
"attachments": {},
514
"cell_type": "markdown",
@@ -23,12 +32,6 @@
2332
"\n",
2433
"In short, we want to make sure that the code can be executed without any errors.\n",
2534
"\n",
26-
"## Step 0: Install the necessary validators from Guardrails Hub\n",
27-
"\n",
28-
"We first have to install the ```ValidPython``` validator from Guardrails Hub:\n",
29-
"\n",
30-
"```guardrails hub install hub://reflex/valid_python```\n",
31-
"\n",
3235
"## Step 1: Generating `RAIL` Spec\n",
3336
"\n",
3437
"Ordinarily, we could create a separate `RAIL` spec in a file. However, for the sake of this example, we will generate the `RAIL` spec in the notebook as a string. We will also show the same RAIL spec in a code-first format using a Pydantic model."
@@ -434,7 +437,7 @@
434437
"name": "python",
435438
"nbconvert_exporter": "python",
436439
"pygments_lexer": "ipython3",
437-
"version": "3.9.17"
440+
"version": "3.12.2"
438441
},
439442
"orig_nbformat": 4,
440443
"vscode": {

docs/examples/competitors_check.ipynb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://guardrails/competitor_check\n"
10+
]
11+
},
312
{
413
"cell_type": "markdown",
514
"metadata": {},

docs/examples/extracting_entities.ipynb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://guardrails/valid_length\n",
10+
"!guardrails hub install hub://guardrails/two_words\n",
11+
"!guardrails hub install hub://guardrails/valid_range"
12+
]
13+
},
314
{
415
"attachments": {},
516
"cell_type": "markdown",
@@ -16,19 +27,11 @@
1627
"\n",
1728
"We want to extract structured information about all fees and interest rates associated with the Chase credit card.\n",
1829
"\n",
19-
"## Step 0: Download PDF and load it as string and Install Validators from Guardrails Hub \n",
30+
"## Step 0: Download PDF and load it as string\n",
2031
"\n",
2132
"To get started, download the document from [here](https://github.com/ShreyaR/guardrails/blob/main/docs/examples/data/chase_card_agreement.pdf) and save it in `data/chase_card_agreement.pdf`.\n",
2233
"\n",
23-
"Guardrails has some built-in functions to help with common tasks. Here, we will use the `read_pdf` function to load the PDF as a string.\n",
24-
"\n",
25-
"We also need to install the necessary validators from Guardrails Hub: \n",
26-
"\n",
27-
"1. LowerCase: ```guardrails hub install hub://guardrails/lowercase```\n",
28-
"\n",
29-
"2. TwoWords: ```guardrails hub install hub://guardrails/two_words```\n",
30-
"\n",
31-
"3. OneLine: ```guardrails hub install hub://guardrails/one_line```"
34+
"Guardrails has some built-in functions to help with common tasks. Here, we will use the `read_pdf` function to load the PDF as a string."
3235
]
3336
},
3437
{

docs/examples/generate_structured_data.ipynb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://reflex/valid_python\n",
10+
"!guardrails hub install hub://guardrails/two_words\n",
11+
"!guardrails hub install hub://guardrails/valid_range"
12+
]
13+
},
314
{
415
"attachments": {},
516
"cell_type": "markdown",
@@ -26,16 +37,6 @@
2637
"3. The number of orders associated with each user should be between 0 and 50.\n",
2738
"4. Each user should have a most recent order date.\n",
2839
"\n",
29-
"## Step 0: Install the necessary validators from Guardrails Hub\n",
30-
"\n",
31-
"We first have to install the necessary validators from Guardrails Hub:\n",
32-
"\n",
33-
"1. ValidLength: ```guardrails hub install hub://reflex/valid_python```\n",
34-
"\n",
35-
"2. TwoWords: ```guardrails hub install hub://guardrails/two_words```\n",
36-
"\n",
37-
"3. ValidRange: ```guardrails hub install hub://guardrails/valid_range```\n",
38-
"\n",
3940
"## Step 1: Generating `RAIL` Spec\n",
4041
"\n",
4142
"Ordinarily, we could create a separate `RAIL` spec in a file. However, for the sake of this example, we will generate the `RAIL` spec in the notebook as a string. We will also show the same RAIL spec in a code-first format using a Pydantic model."

docs/examples/guardrails_with_chat_models.ipynb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://guardrails/lowercase\n",
10+
"!guardrails hub install hub://guardrails/two_words\n",
11+
"!guardrails hub install hub://guardrails/one_line"
12+
]
13+
},
314
{
415
"attachments": {},
516
"cell_type": "markdown",
@@ -16,19 +27,11 @@
1627
"\n",
1728
"We retry the [entity extraction example](./extracting_entities.ipynb) using a chat model.\n",
1829
"\n",
19-
"## Step 0: Download PDF and load it as string and Install Validators from Guardrails Hub\n",
30+
"## Step 0: Download PDF and load it as string\n",
2031
"\n",
2132
"To get started, download the document from [here](https://github.com/guardrails-ai/guardrails/blob/main/docs/examples/data/chase_card_agreement.pdf) and save it in `data/chase_card_agreement.pdf`.\n",
2233
"\n",
23-
"Guardrails has some built-in functions to help with common tasks. Here, we will use the `read_pdf` function to load the PDF as a string.\n",
24-
"\n",
25-
"We also need to install the necessary validators from Guardrails Hub: \n",
26-
"\n",
27-
"1. LowerCase: ```guardrails hub install hub://guardrails/lowercase```\n",
28-
"\n",
29-
"2. TwoWords: ```guardrails hub install hub://guardrails/two_words```\n",
30-
"\n",
31-
"3. OneLine: ```guardrails hub install hub://guardrails/one_line```"
34+
"Guardrails has some built-in functions to help with common tasks. Here, we will use the `read_pdf` function to load the PDF as a string."
3235
]
3336
},
3437
{

docs/examples/input_validation.ipynb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://guardrails/two_words"
10+
]
11+
},
312
{
413
"cell_type": "markdown",
514
"metadata": {},
615
"source": [
716
"## Input Validation\n",
817
"\n",
9-
"Guardrails supports validating inputs (prompts, instructions, msg_history) with string validators.\n",
10-
"\n",
11-
"We first have to install the ```TwoWords``` validator from Guardrails Hub: \n",
12-
"\n",
13-
"```guardrails hub install hub://guardrails/two_words```"
18+
"Guardrails supports validating inputs (prompts, instructions, msg_history) with string validators."
1419
]
1520
},
1621
{

docs/examples/provenance.ipynb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://guardrails/provenance_embeddings\n",
10+
"!guardrails hub install hub://guardrails/provenance_llm"
11+
]
12+
},
313
{
414
"attachments": {},
515
"cell_type": "markdown",
@@ -35,11 +45,7 @@
3545
"For the sake of this post, let's use the following configuration for our validator:\n",
3646
"\n",
3747
"1. `sources`: List of strings, each representing a source.\n",
38-
"2. `embed function`: A function that takes a list of strings of length k and returns a 2D numpy array of shape (k, embedding_dim).\n",
39-
"\n",
40-
"We first have to install the ```ProvenanceEmbeddings``` validator from Guardrails Hub: \n",
41-
"\n",
42-
"```guardrails hub install hub://guardrails/provenance_embeddings```"
48+
"2. `embed function`: A function that takes a list of strings of length k and returns a 2D numpy array of shape (k, embedding_dim)."
4349
]
4450
},
4551
{
@@ -485,11 +491,7 @@
485491
"\n",
486492
"- Set the OPENAI_API_KEY environment variable: os.environ[\"OPENAI_API_KEY\"] = \"[OpenAI_API_KEY]\"\n",
487493
"- Set the OPENAI_API_KEY using openai.api_key=\"[OpenAI_API_KEY]\"\n",
488-
"- Pass the api_key as a parameter to the parse function as done below, in this example\n",
489-
"\n",
490-
"We first install the ```ProvenanceLLM``` validator from Guardrails Hub: \n",
491-
"\n",
492-
"```guardrails hub install hub://guardrails/provenance_llm```"
494+
"- Pass the api_key as a parameter to the parse function as done below, in this example"
493495
]
494496
},
495497
{

docs/examples/regex_validation.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://guardrails/regex_match"
10+
]
11+
},
312
{
413
"cell_type": "markdown",
514
"metadata": {},
@@ -27,15 +36,6 @@
2736
"regex = '\\\\d{3}-\\\\d{3}-\\\\d{4}'"
2837
]
2938
},
30-
{
31-
"cell_type": "markdown",
32-
"metadata": {},
33-
"source": [
34-
"### Install the ```RegexMatch``` validator from Guardrails Hub \n",
35-
"\n",
36-
"```guardrails hub install hub://guardrails/regex_match```"
37-
]
38-
},
3939
{
4040
"cell_type": "markdown",
4141
"metadata": {},

docs/examples/response_is_on_topic.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://tryolabs/restricttotopic"
10+
]
11+
},
312
{
413
"cell_type": "markdown",
514
"metadata": {},
@@ -92,15 +101,6 @@
92101
"The argument `model` indicates the model that will be used to classify the topic. See a list of all models [here](https://huggingface.co/models?pipeline_tag=zero-shot-classification&sort=trending)."
93102
]
94103
},
95-
{
96-
"cell_type": "markdown",
97-
"metadata": {},
98-
"source": [
99-
"## Install the ```RestrictToTopic``` validator from Guardrails Hub \n",
100-
"\n",
101-
"```guardrails hub install hub://tryolabs/restricttotopic```\n"
102-
]
103-
},
104104
{
105105
"cell_type": "markdown",
106106
"metadata": {},

docs/examples/secrets_detection.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!guardrails hub install hub://guardrails/secrets_present"
10+
]
11+
},
312
{
413
"cell_type": "markdown",
514
"metadata": {},
@@ -31,15 +40,6 @@
3140
"! pip install detect-secrets -q"
3241
]
3342
},
34-
{
35-
"cell_type": "markdown",
36-
"metadata": {},
37-
"source": [
38-
"We also need to install the ```SecretsPresent``` validator from Guardrails Hub: \n",
39-
"\n",
40-
"```guardrails hub install hub://guardrails/secrets_present```"
41-
]
42-
},
4343
{
4444
"cell_type": "code",
4545
"execution_count": null,

0 commit comments

Comments
 (0)