Skip to content

Commit 44fabaa

Browse files
committed
from_* -> for_*
1 parent 2fa0d6c commit 44fabaa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+347
-304
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ prompt = """
147147
148148
${gr.complete_json_suffix_v2}
149149
"""
150-
guard = Guard.from_pydantic(output_class=Pet, prompt=prompt)
150+
guard = Guard.for_pydantic(output_class=Pet, prompt=prompt)
151151
152152
raw_output, validated_output, *rest = guard(
153153
llm_api=openai.completions.create,

docs/api_reference/async_guard.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
options:
66
members:
77
- "__init__"
8-
- "from_rail"
9-
- "from_rail_string"
10-
- "from_pydantic"
11-
- "from_string"
8+
- "for_rail"
9+
- "for_rail_string"
10+
- "for_pydantic"
11+
- "for_string"
1212
- "configure"
1313
- "use"
1414
- "use_many"

docs/api_reference/guard.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
options:
66
members:
77
- "__init__"
8-
- "from_rail"
9-
- "from_rail_string"
10-
- "from_pydantic"
8+
- "for_rail"
9+
- "for_rail_string"
10+
- "for_pydantic"
1111
- "from_string"
1212
- "configure"
1313
- "use"

docs/concepts/logs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Calls can be further decomposed into a stack of `Iteration` objects. These are s
99
## General Access
1010
Given:
1111
```py
12-
my_guard = Guard.from_pydantic(...)
12+
my_guard = Guard.for_pydantic(...)
1313

1414
response_1 = my_guard(...)
1515

docs/concepts/streaming_structured_data.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
"metadata": {},
123123
"outputs": [],
124124
"source": [
125-
"guard = gd.Guard.from_pydantic(output_class=PatientInfo)"
125+
"guard = gd.Guard.for_pydantic(output_class=PatientInfo)"
126126
]
127127
},
128128
{

docs/concepts/validators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Occasionally, validators need additional metadata that is only available during
1515
As an example, the `ExtractedSummarySentencesMatch` validator accepts a `filepaths` property in the metadata dictionary to specify what source files to compare the summary against to ensure similarity. Unlike arguments which are specified at validator initialization, metadata is specified when calling `guard.validate` or `guard.__call__` (this is the `guard()` function).
1616

1717
```python
18-
guard = Guard.from_rail("my_railspec.rail")
18+
guard = Guard.for_rail("my_railspec.rail")
1919

2020
outcome = guard(
2121
llm_api=openai.chat.completions.create,
Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,93 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": 4,
6-
"metadata": {},
7-
"outputs": [
8-
{
9-
"name": "stdout",
10-
"output_type": "stream",
11-
"text": [
12-
"\n",
13-
"\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;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1\u001b[0m\n",
14-
"\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",
15-
"\n",
16-
"\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;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1\u001b[0m\n",
17-
"\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"
18-
]
19-
}
20-
],
21-
"source": [
22-
"! pip install ipywidgets -q"
23-
]
24-
},
25-
{
26-
"cell_type": "code",
27-
"execution_count": 1,
28-
"metadata": {},
29-
"outputs": [
30-
{
31-
"data": {
32-
"application/vnd.jupyter.widget-view+json": {
33-
"model_id": "81b91198c45249a2b0a7075d13ebf838",
34-
"version_major": 2,
35-
"version_minor": 0
36-
},
37-
"text/plain": [
38-
"model.safetensors: 0%| | 10.5M/2.20G [00:00<?, ?B/s]"
39-
]
40-
},
41-
"metadata": {},
42-
"output_type": "display_data"
43-
}
44-
],
45-
"source": [
46-
"from guardrails import Guard\n",
47-
"from pydantic import BaseModel\n",
48-
"\n",
49-
"class Dog(BaseModel):\n",
50-
" name: str\n",
51-
" color: str\n",
52-
" weight_kg: float\n",
53-
"\n",
54-
"class NewFriends(BaseModel):\n",
55-
" dogs: list[Dog]\n",
56-
"\n",
57-
"guard = Guard.from_pydantic(NewFriends, output_formatter=\"jsonformer\")\n",
58-
"\n",
59-
"# JSONFormer is only compatible with HF Pipelines and HF Models:\n",
60-
"from transformers import pipeline\n",
61-
"tiny_llama_pipeline = pipeline(\"text-generation\", \"TinyLlama/TinyLlama-1.1B-Chat-v1.0\")\n",
62-
"\n",
63-
"# Inference is straightforward:\n",
64-
"response = guard(tiny_llama_pipeline, prompt=\"Please enjoy this list of good dogs:\")\n",
65-
"\n",
66-
"# `out` is a dict. Format it as JSON for readability:\n",
67-
"import json\n",
68-
"print(json.dumps(response.validated_output, indent=2))"
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 4,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"\n",
13+
"\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;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1\u001b[0m\n",
14+
"\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",
15+
"\n",
16+
"\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;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1\u001b[0m\n",
17+
"\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"
18+
]
19+
}
20+
],
21+
"source": [
22+
"! pip install ipywidgets -q"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 1,
28+
"metadata": {},
29+
"outputs": [
30+
{
31+
"data": {
32+
"application/vnd.jupyter.widget-view+json": {
33+
"model_id": "81b91198c45249a2b0a7075d13ebf838",
34+
"version_major": 2,
35+
"version_minor": 0
36+
},
37+
"text/plain": [
38+
"model.safetensors: 0%| | 10.5M/2.20G [00:00<?, ?B/s]"
6939
]
70-
}
71-
],
72-
"metadata": {
73-
"kernelspec": {
74-
"display_name": ".venv",
75-
"language": "python",
76-
"name": "python3"
7740
},
78-
"language_info": {
79-
"codemirror_mode": {
80-
"name": "ipython",
81-
"version": 3
82-
},
83-
"file_extension": ".py",
84-
"mimetype": "text/x-python",
85-
"name": "python",
86-
"nbconvert_exporter": "python",
87-
"pygments_lexer": "ipython3",
88-
"version": "3.12.3"
89-
}
90-
},
91-
"nbformat": 4,
92-
"nbformat_minor": 2
93-
}
41+
"metadata": {},
42+
"output_type": "display_data"
43+
}
44+
],
45+
"source": [
46+
"from guardrails import Guard\n",
47+
"from pydantic import BaseModel\n",
48+
"\n",
49+
"class Dog(BaseModel):\n",
50+
" name: str\n",
51+
" color: str\n",
52+
" weight_kg: float\n",
53+
"\n",
54+
"class NewFriends(BaseModel):\n",
55+
" dogs: list[Dog]\n",
56+
"\n",
57+
"guard = Guard.for_pydantic(NewFriends, output_formatter=\"jsonformer\")\n",
58+
"\n",
59+
"# JSONFormer is only compatible with HF Pipelines and HF Models:\n",
60+
"from transformers import pipeline\n",
61+
"tiny_llama_pipeline = pipeline(\"text-generation\", \"TinyLlama/TinyLlama-1.1B-Chat-v1.0\")\n",
62+
"\n",
63+
"# Inference is straightforward:\n",
64+
"response = guard(tiny_llama_pipeline, prompt=\"Please enjoy this list of good dogs:\")\n",
65+
"\n",
66+
"# `out` is a dict. Format it as JSON for readability:\n",
67+
"import json\n",
68+
"print(json.dumps(response.validated_output, indent=2))"
69+
]
70+
}
71+
],
72+
"metadata": {
73+
"kernelspec": {
74+
"display_name": ".venv",
75+
"language": "python",
76+
"name": "python3"
77+
},
78+
"language_info": {
79+
"codemirror_mode": {
80+
"name": "ipython",
81+
"version": 3
82+
},
83+
"file_extension": ".py",
84+
"mimetype": "text/x-python",
85+
"name": "python",
86+
"nbconvert_exporter": "python",
87+
"pygments_lexer": "ipython3",
88+
"version": "3.11.7"
89+
}
90+
},
91+
"nbformat": 4,
92+
"nbformat_minor": 2
93+
}

docs/examples/extracting_entities.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
"metadata": {},
198198
"outputs": [],
199199
"source": [
200-
"guard = gd.Guard.from_pydantic(output_class=CreditCardAgreement)"
200+
"guard = gd.Guard.for_pydantic(output_class=CreditCardAgreement)"
201201
]
202202
},
203203
{

docs/examples/generate_structured_data.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"metadata": {},
134134
"outputs": [],
135135
"source": [
136-
"guard = gd.Guard.from_pydantic(output_class=Orders)"
136+
"guard = gd.Guard.for_pydantic(output_class=Orders)"
137137
]
138138
},
139139
{

docs/examples/generate_structured_data_cohere.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
"source": [
155155
"from rich import print\n",
156156
"import guardrails as gd\n",
157-
"guard = gd.Guard.from_pydantic(output_class=Orders)\n",
157+
"guard = gd.Guard.for_pydantic(output_class=Orders)\n",
158158
"\n",
159159
"raw_llm_response, validated_response, *rest = guard(\n",
160160
" \tmessages=[{\"role\":\"user\", \"content\":prompt}],\n",

0 commit comments

Comments
 (0)