Skip to content

Commit 75e6c4c

Browse files
committed
Merge remote-tracking branch 'origin/main' into update_auth_required_install_msg
2 parents dc56d56 + 32a1ce1 commit 75e6c4c

File tree

74 files changed

+1189
-811
lines changed

Some content is hidden

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

74 files changed

+1189
-811
lines changed

.github/workflows/install_from_hub.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
jobs:
1010
install_from_hub:
1111
runs-on: ubuntu-latest
12+
env:
13+
GUARDRAILS_API_KEY: ${{ secrets.GUARDRAILS_API_KEY }}
1214
steps:
1315
- name: Set up Python
1416
uses: actions/setup-python@v5
@@ -17,6 +19,8 @@ jobs:
1719
- name: pip install from main
1820
run: pip install git+https://github.com/guardrails-ai/guardrails.git@main
1921
- name: Install PII validator
20-
run: guardrails hub install hub://guardrails/detect_pii
22+
run: |
23+
guardrails configure --token $GUARDRAILS_API_KEY --disable-metrics --enable-remote-inferencing;
24+
guardrails hub install hub://guardrails/detect_pii;
2125
- name: Verify PII validator is addressable
2226
run: echo 'from guardrails.hub import DetectPII' | python

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: 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/concepts/error_remediation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Guardrails provides a number of `OnFailActions` for when a validator fails. The
3737
| `OnFailAction.FIX_REASK` | First, fix the generated output deterministically, and then rerun validation with the deterministically fixed output. If validation fails, then perform reasking. | No |
3838

3939

40+
Custom OnFailActions can also be implemented, see the `custom` section in the [how to use on fail actions guide](../how_to_guides/use_on_fail_actions).
41+
4042
## Guidance on dealing with Validator errors
4143

4244
When a validator fails, Guardrails does two things

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: 295 additions & 389 deletions
Large diffs are not rendered by default.

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
{

0 commit comments

Comments
 (0)