Skip to content

Commit b93a9b7

Browse files
authored
Merge pull request #500 from guardrails-ai/0.3.x-migration-doc
start 0.3.x migration guide
2 parents 0ab248d + 58f13c9 commit b93a9b7

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

docs/0-3-migration.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Migrating to 0.3.0
2+
3+
The 0.3.0 release contains a handful of breaking changes compared to the previous 0.2.x releases. This guide will list out these changes as well as how to migrate to the new features that encompass them in 0.3.x.
4+
5+
## Guardrails Response Object
6+
_Validation Outcome_
7+
8+
Previous when calling `__call__` or `parse` on a Guard, the Guard would return a tuple of the raw llm output and the validated output or just the validated output respecitvely.
9+
10+
Now, in order to communicate more information, we respond with a `ValidationOutcome` class that contains the above information and more. See [ValidationOutcome](/api_reference/validation_outcome/#ValidationOutcome) in the API Reference for more information on these additioanl properties.
11+
12+
In order to limit how much this changes breaks the current experience, we made this class iterable so you can still deconstruct its properties.
13+
14+
Whereas in `0.2.x` you would receive the response like so:
15+
```py
16+
guard = Guard(...)
17+
18+
raw_output, validated_output = guard(...)
19+
# or
20+
validated_output = guard.parse(...)
21+
```
22+
23+
You can now keep a similar experience by adding a rest argument at the end:
24+
```py
25+
guard = Guard(...)
26+
27+
raw_output, validated_output, *rest = guard(...)
28+
# or
29+
raw_output, validated_output, *rest = guard.parse(...)
30+
```
31+
32+
You can also simple use the response in its object form:
33+
```py
34+
guard = Guard(...)
35+
36+
response = guard(...)
37+
# or
38+
response = guard.parse(...)
39+
40+
validated_output = response.validated_output
41+
```
42+
43+
One new property that we want to highlight on this return structure is `validation_passed` field. This field is a boolean that will be `True` if the guard process resulted in valid output and `False` otherwise. In conjunction with this, `ValidationOutcome.validated_output` will only have a value if validation succeeded. If the end result was not valid and either was or still contained reasks, `validated_output` will be none and the invalid output will be captured on `ValidationOutcome.reask`.
44+
45+
## History & Logs Improvements
46+
If you're familiar with Guardrails, then you might have used the `Guard.state` property to inspect how the Guard process behaved over time. In order to make the Guard process more transparent, as part of `v0.3.0` we redesigned how you access this information.
47+
48+
Now, on a Guard, you can access logs related to any `__call__` or `parse` call within the current session via `Guard.history`. We documented this new structure and how it works [here](/concepts/logs), but to give a quick example of the differences, where before if you needed to check if validation of a particualr step succeeded or not you might need to do something like this:
49+
```py
50+
guard_history = guard.state.most_recent_call
51+
last_step_logs: GuardLogs = guard_history.history[-1]
52+
validation_logs = last_step_logs.field_validation_logs.validator_logs
53+
failed_validations = list([log for log in validation_logs if log.validation_result.outcome == 'fail'])
54+
validation_succeeded = len(failed_validations) == 0
55+
```
56+
57+
now you can check via:
58+
```py
59+
guard.history.last.status
60+
```
61+
62+
Another quick example, in order to check your total token consumption in `v0.2.0`:
63+
```py
64+
latest_call = guard.state.most_recent_call
65+
66+
total_token_count = 0
67+
for log in latest_call.history:
68+
total_token_count = total_token_count + log.llm_response.prompt_token_count
69+
total_token_count = total_token_count + log.llm_response.response_token_count
70+
```
71+
72+
Now, in `v0.3.0` you can simply:
73+
```py
74+
guard.history.last.tokens_consumed
75+
```
76+
77+
Besides the examples above, if you dive deeper into the new history structure you can find more insights into exactly how the LLM was called in each step of the process. See [here](/concepts/logs) for more details.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: guardrails.classes.validation_outcome

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ nav:
1616
- 'Getting Started': guardrails_ai/getting_started.ipynb
1717
- 'Installation': guardrails_ai/installation.md
1818
- 'Migrating to 0.2.x': 0-2-migration.md
19+
- 'Migrating to 0.3.x': 0-3-migration.md
1920
- 'FAQ': faq.md
2021
- 'Defining Guardrails':
2122
- 'Pydantic': defining_guards/pydantic.ipynb
@@ -33,6 +34,7 @@ nav:
3334
- 'Guard': api_reference/guard.md
3435
- 'Rail': api_reference/rail.md
3536
- 'Validators': api_reference/validators.md
37+
- 'Validation Outcome': api_reference/validation_outcome.md
3638
- 'Response Structures': api_reference/response_structures.md
3739
- 'Schema': api_reference/schema.md
3840
- 'Document Store': api_reference/document_store.md

0 commit comments

Comments
 (0)