WEBVTT

00:00.840 --> 00:08.440
Let's explore how to enhance content moderation by chaining validators using the guardrails AI framework.

00:09.960 --> 00:18.960
Validator chaining allows us to apply multiple content rules sequentially, ensuring comprehensive content

00:18.960 --> 00:19.920
assessment.

00:22.560 --> 00:25.440
We begin by importing necessary modules.

00:27.240 --> 00:36.720
Guard is the core class from guardrails that orchestrates the validation process.

00:37.480 --> 00:44.880
The competitor check and toxic language validators are specialized validators for identifying specific

00:44.880 --> 00:50.640
content issues.

00:50.640 --> 00:57.520
Setting up our validators is the first step in crafting a robust content moderation pipeline.

00:59.560 --> 01:07.160
We define a list of competitors to watch for ensuring our content remains focused on our offerings.

01:11.200 --> 01:18.040
Next, we initialize guard object, chaining our validators using guards use many method.

01:21.280 --> 01:31.440
This setup ensures that any content we validate is checked both for unintended competitors and for toxic

01:31.440 --> 01:32.120
language.

01:36.240 --> 01:48.600
We have also defined a strategy to fix any competitor mentions and raise an exception if a toxic language

01:48.600 --> 01:50.440
is found in the output.

01:55.480 --> 02:00.560
With our validators configured, we proceed to validate a sample text.

02:05.840 --> 02:13.400
This demonstrates the sequential application of our content rules addressing both competitive neutrality

02:13.400 --> 02:15.200
and language positivity.

02:18.760 --> 02:25.400
This is the text we are simulating as an output of LLM and that will be validated using guard object.

02:26.440 --> 02:33.320
The text says my favorite phone is Sony Vue and followed by some toxic language.

02:34.480 --> 02:43.680
As you can see, there is no mention of the competitor here and hence the guardrails.

02:44.120 --> 02:54.000
I would pass this completed check, but should raise an exception as it detects the toxic language.

02:56.770 --> 03:00.330
Let's run the application and see how the output works.

03:17.210 --> 03:25.930
It takes a while to execute the program, but as you can see here in the output, the validation failed

03:25.930 --> 03:27.690
for filled with errors.

03:28.330 --> 03:32.170
The generated text was found to be toxic or inserting.

03:34.250 --> 03:45.570
And if I could just change the validation strategy from exception to fix, the program should just filter

03:45.610 --> 03:50.130
out the output.

03:58.530 --> 04:06.450
In this case, the control should come here in the print statement and we should be able to see what

04:06.450 --> 04:10.810
is the validated response output from guards validated object.

04:11.650 --> 04:17.810
As you can see, the row output that we simulated is the one that we provided in the argument.

04:18.850 --> 04:29.450
But the validated output is empty or none because we changed the strategy from exception to fix.

04:29.450 --> 04:36.970
Validator chaining is a powerful feature of guardrails, enabling us to enforce multiple content guidelines

04:36.970 --> 04:37.730
seamlessly.

04:38.530 --> 04:44.850
By combining these two validators together, we ensure that our content upholds brand integrity and

04:44.850 --> 04:51.170
fosters a positive community environment.
