Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Outcome #431

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d440574
start validation outcome changes
CalebCourier Sep 6, 2023
6223bed
fix gather_reasks for non-structured output
CalebCourier Sep 7, 2023
e5cd3a0
lint fixes
CalebCourier Sep 7, 2023
89e79e6
more lint fixes
CalebCourier Sep 7, 2023
0a60c3e
start test fixes, debug types
CalebCourier Sep 7, 2023
dc60026
fix tests
CalebCourier Sep 18, 2023
3b667dd
fix types with overloads
CalebCourier Sep 18, 2023
adfda53
fix tests
CalebCourier Sep 18, 2023
5fa638a
lint fixes
CalebCourier Sep 18, 2023
c9f7b15
lint fixes
CalebCourier Sep 18, 2023
184891b
fix tests
CalebCourier Sep 18, 2023
9c985bb
lint fixes
CalebCourier Sep 18, 2023
57357fb
switch to generics for ValidationOutcome
CalebCourier Sep 18, 2023
521fe6a
allow destructuring
CalebCourier Sep 18, 2023
8b6c71d
remove None from generic type
CalebCourier Sep 20, 2023
86fd20e
init commit, changes to handle error in guard
Sep 21, 2023
ca55b4f
handle error a layer deeper
Sep 21, 2023
db98409
update return in text2sql
Sep 21, 2023
2d9c694
remove extra fx in validation outcome
Sep 21, 2023
0127b9f
use error instead of exception
Sep 21, 2023
ec12312
remove print statements plus lint
Sep 21, 2023
3bd4b0e
fix type
CalebCourier Oct 31, 2023
82bb11c
fix typing while maintaining type hinting
CalebCourier Nov 2, 2023
7ac019e
fix other type issues
CalebCourier Nov 2, 2023
0b6c73e
autoformat
CalebCourier Nov 2, 2023
14038b4
lint fixes
CalebCourier Nov 2, 2023
eccabb0
test fixes
CalebCourier Nov 2, 2023
2188b9c
autoformat
CalebCourier Nov 2, 2023
1595134
type fixes
CalebCourier Nov 3, 2023
a1dbc94
lint fix
CalebCourier Nov 3, 2023
7a05a27
unused import
CalebCourier Nov 3, 2023
37013bb
uncomment test parameters
CalebCourier Nov 3, 2023
e2fbb37
merge/type fixes
CalebCourier Nov 3, 2023
2eddb2a
guard: Allow calling parse with preconfigured num_reasks (#423)
irgolic Nov 3, 2023
5d2321a
Cron nb (#425)
zsimjee Nov 3, 2023
4ef1e32
fix bad merge in code originally from validators.py (#427)
CalebCourier Nov 3, 2023
39b9c0c
bump version (#428)
CalebCourier Nov 3, 2023
bcc4bb3
update notebooks
CalebCourier Nov 3, 2023
8e90017
Setup passed password (#429)
zsimjee Nov 3, 2023
73b6bc1
Merge branch 'guardrails-ai:main' into validation-outcome-cherrypick
CalebCourier Nov 3, 2023
478c79a
list -> List
CalebCourier Nov 3, 2023
a2c821d
Merge branch 'main' into validation-outcome-cherrypick
CalebCourier Nov 17, 2023
102714c
lint and test fixes
CalebCourier Nov 17, 2023
b768e51
autoformat
CalebCourier Nov 17, 2023
d342b0b
Merge branch 'main' into validation-outcome-cherrypick
CalebCourier Nov 21, 2023
fe154fa
lint and type fix
CalebCourier Nov 21, 2023
d82cbcc
fix test
CalebCourier Nov 21, 2023
338ebb8
fix llm_output type
CalebCourier Nov 21, 2023
c8caf3f
' -> "
CalebCourier Nov 21, 2023
d6666f1
Merge branch 'main' into validation-outcome-cherrypick
CalebCourier Nov 22, 2023
518fa9e
fix tests
CalebCourier Nov 22, 2023
c67c0d6
lint fixes
CalebCourier Nov 22, 2023
e7827df
fix notebooks again
CalebCourier Nov 22, 2023
ec894df
fix docs
CalebCourier Nov 22, 2023
ac178f4
debug
CalebCourier Nov 22, 2023
289c0ac
validated_response -> validated_output
CalebCourier Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Call the `Guard` object with the LLM API call as the first argument and add any
import openai

# Wrap the OpenAI API call with the `guard` object
raw_llm_output, validated_output = guard(
raw_llm_output, validated_output, *rest = guard(
openai.Completion.create,
engine="text-davinci-003",
max_tokens=1024,
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ from guardrails import Guard

guard = Guard.from_rail(...)

raw_output, validated_output = guard(
raw_output, validated_output, *rest = guard(
openai.Completion.create,
engine="text-davinci-003",
max_tokens=1024,
Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Sometimes validators need addtional parameters that are only availble during run
```python
guard = Guard.from_rail("my_railspec.rail")

raw_output, guarded_output = guard(
raw_output, guarded_output, *rest = guard(
llm_api=openai.ChatCompletion.create,
model="gpt-3.5-turbo",
num_reasks=3,
Expand Down Expand Up @@ -134,7 +134,7 @@ ${guardrails.complete_json_suffix}

guard = Guard.from_rail_string(rail_string=rail_str)

raw_output, guarded_output = guard(
raw_output, guarded_output, *rest = guard(
llm_api=openai.ChatCompletion.create,
model="gpt-3.5-turbo"
)
Expand Down
6 changes: 3 additions & 3 deletions docs/defining_guards/pydantic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"\"\"\"\n",
"guard = Guard.from_pydantic(output_class=Pet, prompt=prompt)\n",
"\n",
"raw_llm_output, validated_output = guard(\n",
"raw_llm_output, validated_output, *rest = guard(\n",
" llm_api=openai.Completion.create,\n",
" engine=\"text-davinci-003\"\n",
")\n",
Expand Down Expand Up @@ -378,7 +378,7 @@
"\n",
"guard = Guard.from_pydantic(output_class=Pet, prompt=prompt)\n",
"\n",
"raw_llm_output, validated_output = guard(\n",
"raw_llm_output, validated_output, *rest = guard(\n",
" llm_api=openai.Completion.create,\n",
" engine=\"text-davinci-003\",\n",
" max_tokens=1024,\n",
Expand Down Expand Up @@ -576,7 +576,7 @@
"\"\"\"\n",
"\n",
"guard = Guard.from_pydantic(output_class=Pet, prompt=prompt)\n",
"raw_llm_output, validated_output = guard(\n",
"raw_llm_output, validated_output, *rest = guard(\n",
" llm_api=openai.Completion.create,\n",
" engine=\"text-davinci-003\",\n",
" max_tokens=1024,\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/defining_guards/rail.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import guardrails as gd

# Create a Guard object
guard = gd.Guard.from_rail('path/to/rail/spec.xml') # (1)!
validated_output = guard(
_, validated_output, *rest = guard(
openai.Completion.create, # (2)!
**prompt_args,
*args,
Expand Down
2 changes: 1 addition & 1 deletion docs/defining_guards/strings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
" prompt=\"Generate a puppy name\"\n",
")\n",
"\n",
"raw_llm_output, validated_llm_response = guard(openai.Completion.create)\n",
"raw_llm_output, validated_llm_response, *rest = guard(openai.Completion.create)\n",
"print(validated_llm_response)\n",
"print(guard.state.most_recent_call.tree)"
]
Expand Down
44 changes: 19 additions & 25 deletions docs/examples/bug_free_python_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -75,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -113,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -131,18 +131,9 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/zaydsimjee/workspace/guardrails/guardrails/validatorsattr.py:285: UserWarning: Validator bug-free-python is not valid for element pythoncode.\n",
" warnings.warn(\n"
]
}
],
"outputs": [],
"source": [
"guard = gd.Guard.from_rail_string(rail_str)"
]
Expand All @@ -156,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -173,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -254,7 +245,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -264,7 +255,7 @@
"Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.\n",
"\"\"\"\n",
"\n",
"raw_llm_response, validated_response = guard(\n",
"response = guard(\n",
" openai.Completion.create,\n",
" prompt_params={\"leetcode_problem\": leetcode_problem},\n",
" engine=\"text-davinci-003\",\n",
Expand All @@ -285,7 +276,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -313,7 +304,7 @@
}
],
"source": [
"print(validated_response)"
"print(response.validated_output)"
]
},
{
Expand All @@ -326,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -358,7 +349,10 @@
}
],
"source": [
"print(validated_response[\"python_code\"])"
"if response.validated_output is not None:\n",
" print(response.validated_output[\"python_code\"])\n",
"elif response.error is not None:\n",
" print(response.error)"
]
},
{
Expand All @@ -371,7 +365,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -390,7 +384,7 @@
],
"source": [
"try:\n",
" exec(validated_response[\"python_code\"])\n",
" exec(response.validated_output[\"python_code\"])\n",
" print(\"Success!\")\n",
"except Exception as e:\n",
" print(\"Failed!\")"
Expand All @@ -413,7 +407,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.6"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
Loading
Loading