WEBVTT

00:01.080 --> 00:05.200
Let's explore another example wherein we will use guardrails.

00:05.240 --> 00:14.720
AI's framework to validate the output generated by LLM, to ensure that it doesn't inadvertently mention

00:14.720 --> 00:18.880
competitor's name in the output.

00:19.600 --> 00:23.800
The program begins by importing the necessary libraries.

00:25.080 --> 00:34.480
In this case, it imports base model and field classes from parenthesis, which are used to define models

00:34.640 --> 00:35.760
and their fields.

00:37.160 --> 00:42.440
Followed by importing a competitor check class from guardrails validator.

00:44.040 --> 00:50.320
And then we are importing guard object and reach print for formatting the output.

00:53.400 --> 00:55.240
Let's initialize the validator.

00:55.280 --> 01:04.080
Here we use competitor check to ensure our product description doesn't mention the competitor's name.

01:05.760 --> 01:15.850
We list our competitors Named Burger Haven and Sub Wraps and specify an action to take if the validation

01:15.850 --> 01:21.290
fails, such as fixing the error or throwing an exception.

01:24.970 --> 01:30.130
Next, we define a parent model for our products.

01:31.450 --> 01:35.090
This model includes product name and description.

01:36.690 --> 01:45.930
Importantly, we apply our validator to the description field, ensuring it adheres to the specifications.

01:50.050 --> 01:55.330
Now, with our model and validators in place, we create a guard object.

01:58.490 --> 02:06.010
This object will check LLM generated outputs to ensure they match our parenting model, essentially

02:06.010 --> 02:08.250
enforcing our validation rules.

02:12.690 --> 02:16.780
Let's simulate receiving an LLM generated product.

02:16.780 --> 02:17.660
Description.

02:19.260 --> 02:25.860
Our goal is to validate this output against our rules, ensuring no mention of competitors.

02:27.660 --> 02:33.860
We use our guard object to parse and validate the output m.

02:37.020 --> 02:38.180
Upon validation.

02:38.900 --> 02:47.740
If the output mentions a competitor, our guard will attempt to raise an exception based on our failed

02:47.740 --> 02:48.620
strategy.

02:53.700 --> 02:55.220
Let's run this example.

02:57.820 --> 02:59.220
And see the output.

03:15.140 --> 03:23.670
As you can see, the validation failed for the description field because it found the name of competitor

03:24.070 --> 03:25.750
here in the description.

03:30.950 --> 03:41.310
Let's change the strategy from raising an exception to fixing the output and run this program again.

04:00.310 --> 04:01.710
As you can see here.

04:04.670 --> 04:13.630
The output validated by guardrails AI framework removes the description details because it has mention

04:13.670 --> 04:15.190
of the compiler.

04:16.190 --> 04:23.310
So it fixed the output by removing the required details.

04:23.310 --> 04:27.190
This is how the computer checks work in AI guardrails.
