Skip to content

Commit 960b87e

Browse files
committed
from_string -> for_string
1 parent 61d8377 commit 960b87e

File tree

12 files changed

+454
-499
lines changed

12 files changed

+454
-499
lines changed

docs/api_reference/guard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- "for_rail"
99
- "for_rail_string"
1010
- "for_pydantic"
11-
- "from_string"
11+
- "for_string"
1212
- "configure"
1313
- "use"
1414
- "use_many"

docs/concepts/streaming_structured_data.ipynb

Lines changed: 294 additions & 388 deletions
Large diffs are not rendered by default.

docs/examples/provenance.ipynb

Lines changed: 70 additions & 65 deletions
Large diffs are not rendered by default.

docs/examples/regex_validation.ipynb

Lines changed: 39 additions & 22 deletions
Large diffs are not rendered by default.

docs/examples/response_is_on_topic.ipynb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
},
5959
{
6060
"cell_type": "code",
61-
"execution_count": 6,
61+
"execution_count": 2,
6262
"metadata": {},
6363
"outputs": [],
6464
"source": [
@@ -136,14 +136,24 @@
136136
},
137137
{
138138
"cell_type": "code",
139-
"execution_count": 7,
139+
"execution_count": 5,
140140
"metadata": {},
141141
"outputs": [
142+
{
143+
"name": "stderr",
144+
"output_type": "stream",
145+
"text": [
146+
"/home/zayd/workspace/guardrails/docs/.venv/lib/python3.11/site-packages/sentence_transformers/cross_encoder/CrossEncoder.py:13: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
147+
" from tqdm.autonotebook import tqdm, trange\n",
148+
"/home/zayd/workspace/guardrails/docs/.venv/lib/python3.11/site-packages/guardrails/validator_service/__init__.py:85: UserWarning: Could not obtain an event loop. Falling back to synchronous validation.\n",
149+
" warnings.warn(\n"
150+
]
151+
},
142152
{
143153
"name": "stdout",
144154
"output_type": "stream",
145155
"text": [
146-
"Validation failed for field with errors: Invalid topics found: ['tablet', 'phone', 'computer']\n"
156+
"Validation failed for field with errors: Invalid topics found: ['tablet', 'computer', 'phone']\n"
147157
]
148158
}
149159
],
@@ -153,7 +163,7 @@
153163
"from guardrails.errors import ValidationError\n",
154164
"\n",
155165
"# Create the Guard with the OnTopic Validator\n",
156-
"guard = gd.Guard.from_string(\n",
166+
"guard = gd.Guard.for_string(\n",
157167
" validators=[\n",
158168
" RestrictToTopic(\n",
159169
" valid_topics=valid_topics,\n",
@@ -187,7 +197,7 @@
187197
},
188198
{
189199
"cell_type": "code",
190-
"execution_count": 8,
200+
"execution_count": 6,
191201
"metadata": {},
192202
"outputs": [
193203
{
@@ -233,7 +243,7 @@
233243
},
234244
{
235245
"cell_type": "code",
236-
"execution_count": 9,
246+
"execution_count": 7,
237247
"metadata": {},
238248
"outputs": [
239249
{
@@ -246,7 +256,7 @@
246256
],
247257
"source": [
248258
"# Create the Guard with the OnTopic Validator\n",
249-
"guard = gd.Guard.from_string(\n",
259+
"guard = gd.Guard.for_string(\n",
250260
" validators=[\n",
251261
" RestrictToTopic(\n",
252262
" valid_topics=valid_topics,\n",
@@ -285,7 +295,7 @@
285295
"name": "python",
286296
"nbconvert_exporter": "python",
287297
"pygments_lexer": "ipython3",
288-
"version": "3.12.1"
298+
"version": "3.11.7"
289299
}
290300
},
291301
"nbformat": 4,

docs/examples/secrets_detection.ipynb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"output_type": "stream",
4242
"text": [
4343
"\n",
44-
"\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",
44+
"\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.2\u001b[0m\n",
4545
"\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"
4646
]
4747
}
@@ -55,7 +55,16 @@
5555
"cell_type": "code",
5656
"execution_count": 3,
5757
"metadata": {},
58-
"outputs": [],
58+
"outputs": [
59+
{
60+
"name": "stderr",
61+
"output_type": "stream",
62+
"text": [
63+
"/home/zayd/workspace/guardrails/docs/.venv/lib/python3.11/site-packages/sentence_transformers/cross_encoder/CrossEncoder.py:13: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
64+
" from tqdm.autonotebook import tqdm, trange\n"
65+
]
66+
}
67+
],
5968
"source": [
6069
"# Import the guardrails package\n",
6170
"# and import the SecretsPresent validator\n",
@@ -75,7 +84,7 @@
7584
"# Here, we'll specify that we want to fix\n",
7685
"# if the validator detects secrets\n",
7786
"\n",
78-
"guard = gd.Guard.from_string(\n",
87+
"guard = gd.Guard.for_string(\n",
7988
" validators=[SecretsPresent(on_fail=\"fix\")],\n",
8089
" description=\"testmeout\",\n",
8190
")"
@@ -86,6 +95,14 @@
8695
"execution_count": 5,
8796
"metadata": {},
8897
"outputs": [
98+
{
99+
"name": "stderr",
100+
"output_type": "stream",
101+
"text": [
102+
"/home/zayd/workspace/guardrails/docs/.venv/lib/python3.11/site-packages/guardrails/validator_service/__init__.py:85: UserWarning: Could not obtain an event loop. Falling back to synchronous validation.\n",
103+
" warnings.warn(\n"
104+
]
105+
},
89106
{
90107
"data": {
91108
"text/html": [
@@ -239,7 +256,7 @@
239256
"name": "python",
240257
"nbconvert_exporter": "python",
241258
"pygments_lexer": "ipython3",
242-
"version": "3.12.1"
259+
"version": "3.11.7"
243260
}
244261
},
245262
"nbformat": 4,

docs/how_to_guides/telemetry.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import openai
6161
# use a descriptive name that will differentiate where your metrics are stored
6262
default_otlp_tracer("petname_guard")
6363

64-
guard = Guard.from_string(
64+
guard = Guard.for_string(
6565
validators=[ValidLength(min=1, max=10, on_fail=OnFailAction.EXCEPTION)],
6666
)
6767

@@ -133,7 +133,7 @@ import openai
133133
# use a descriptive name that will differentiate where your metrics are stored
134134
default_otel_collector_tracer("petname_guard")
135135

136-
guard = Guard.from_string(
136+
guard = Guard.for_string(
137137
validators=[ValidLength(min=1, max=10, on_fail=OnFailAction.EXCEPTION)],
138138
)
139139

docs/hub/how_to_guides/metadata.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ val = ProvenanceLLM(
2828
)
2929

3030
# Setup Guard
31-
guard = Guard.from_string(validators=[val])
31+
guard = Guard.for_string(validators=[val])
3232
```
3333

3434
Below, we show how to pass the metadata to the `guard.validate` method.

docs/integrations/telemetry/grafana.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import openai
5252
# use a descriptive name that will differentiate where your metrics are stored
5353
default_otlp_tracer("petname_guard")
5454

55-
guard = Guard.from_string(
55+
guard = Guard.for_string(
5656
validators=[ValidLength(min=1, max=10, on_fail=OnFailAction.EXCEPTION)],
5757
)
5858

docs/llm_api_wrappers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ model_inputs = tokenizer(prompt, return_tensors="pt").to(torch_device)
130130

131131

132132
# Create the Guard
133-
guard = Guard.from_string(
133+
guard = Guard.for_string(
134134
validators=[
135135
ValidLength(
136136
min=48,
@@ -175,7 +175,7 @@ generator = pipeline("text-generation", model="facebook/opt-350m")
175175

176176

177177
# Create the Guard
178-
guard = Guard.from_string(
178+
guard = Guard.for_string(
179179
validators=[
180180
ValidLength(
181181
min=48,

0 commit comments

Comments
 (0)