WEBVTT

00:00.200 --> 00:08.640
Let's explore how to use guardrails AI framework to systematically process and validate medical data

00:08.640 --> 00:11.240
records derived from doctor's notes.

00:14.840 --> 00:18.560
By employing guardrails, AI's a built in validators.

00:19.480 --> 00:27.600
The application underscores the importance of structured data validation in healthcare information processing.

00:30.000 --> 00:34.560
The program starts by importing necessary modules and packages.

00:35.800 --> 00:43.320
Base model and field from parenthesis are used to define data models with specific attributes and validation

00:43.320 --> 00:43.960
rules.

00:46.440 --> 00:55.760
The guardrails framework is represented by GD, which facilitates the validation process alongside valid

00:55.760 --> 00:59.640
range and valid choices.

01:00.230 --> 01:07.230
Additional imports include OpenAI for accessing AI driven text processing capabilities.

01:09.110 --> 01:14.190
JSON for data formatting and reach for enhanced console printing.

01:18.150 --> 01:28.550
The next step would be to define the output model and prompt and build rail specification using these

01:28.550 --> 01:32.390
two components and creating a guard object.

01:33.670 --> 01:44.430
So in this case, the output models are defined using symptom medication and patient info models.

01:46.030 --> 01:47.950
The symptom model captures.

01:50.670 --> 01:54.350
Medical symptoms experienced by a patient.

01:55.430 --> 02:03.370
Each symptom is associated with an effective body part with validation ensuring only specified areas

02:03.370 --> 02:07.170
such as head, neck and chest are accepted.

02:08.250 --> 02:12.490
This precision is crucial for accurate medical record keeping.

02:16.050 --> 02:25.690
The medication model documents medications a patient is taking, including medication name and patient's

02:25.690 --> 02:26.610
response.

02:27.250 --> 02:34.690
This model is essential for tracking treatment efficiency and patient reactions.

02:35.050 --> 02:44.170
Finally, the patient model aggregates comprehensive patient information including gender, age, a

02:44.170 --> 02:46.770
list of symptoms, and current medications.

02:51.610 --> 02:57.930
Age validation checks are realistic values between 0 to 100 years.

02:58.090 --> 03:00.720
Enforcing logical data integrity.

03:04.240 --> 03:06.160
List symptoms and medication.

03:06.280 --> 03:08.440
Tie back to their respective models.

03:08.760 --> 03:12.320
Ensuring a detailed, validated patient profile.

03:15.040 --> 03:21.200
Now that we have defined the output model, let's construct the AI prompt.

03:26.160 --> 03:33.240
A meticulously crafted prompt instructs the AI to analyze the doctor's notes and extract structured

03:33.240 --> 03:39.000
patient information, aligning with defined pydantic models.

03:41.360 --> 03:48.840
This approach leverages AI's potential to interpret complex medical text, transforming unstructured

03:48.840 --> 03:56.160
data into a structured format for further analysis.

03:57.440 --> 04:05.510
In this case, The doctor's notes will be replaced by the value defined in this variable, which states

04:05.510 --> 04:14.430
45 year old male with chronic macular rash to face and hair worse in beard, eyebrows and nares.

04:14.470 --> 04:17.150
Itchy, flaky, slightly scaly.

04:17.430 --> 04:23.230
Moderate response to OTC steroid system.

04:23.230 --> 04:32.550
And finally, this is built in variable within the Gardel serie framework that would define a structured

04:32.550 --> 04:41.150
JSON example that can help the LLM to create a valid JSON structure.

04:41.150 --> 04:51.030
Once the prompts and output models are defined, this presents the base for creating the guard object.

04:52.350 --> 04:58.310
The guard object is instantiated with patient info model, setting the stage for Garters framework to

04:58.350 --> 05:02.210
enforce data validation based on the model's constraints.

05:04.250 --> 05:12.810
This integration is pivotal for translating AI generated insights into validated structures that adhere

05:12.810 --> 05:19.050
to predefined medical and data integrity standards.

05:19.090 --> 05:19.730
Finally.

05:21.850 --> 05:35.770
The call to an LLM is wrapped into the guard object, which basically invokes a call to LLM and validates

05:35.770 --> 05:38.570
the output and performs necessary action.

05:41.370 --> 05:43.170
In this case, we have defined.

05:45.850 --> 05:55.770
That if the affected area of symptom is outside these three varied choices, the LLM should be re-asked

05:55.770 --> 05:57.490
to generate the output.

05:59.120 --> 06:05.200
This action is performed internally by the guardrail CF framework within this call.

06:08.640 --> 06:16.200
Let's execute this program and understand how it works.

06:38.640 --> 06:39.880
As you can see here.

06:42.280 --> 06:50.840
This is the initial step in which the prompt prepared by guardrails AI framework is given as an input

06:50.840 --> 06:51.760
to LLM.

06:52.760 --> 07:00.430
This includes doctors notes and the output model that we are expecting.

07:02.470 --> 07:06.630
Which includes patients gender age in the varied range.

07:07.870 --> 07:10.110
Symptom.

07:10.110 --> 07:12.790
Valid choices current medications.

07:15.710 --> 07:19.150
And then this is the raw LLM output generated by.

07:19.310 --> 07:25.310
LLM which includes gender symptoms and other information.

07:26.270 --> 07:29.190
This output is validated by cartels.

07:29.230 --> 07:35.910
AI framework against the criteria that has been defined in this case.

07:36.350 --> 07:37.470
As you can see here.

07:41.790 --> 07:45.510
Some of the values doesn't match our valid choices.

07:45.510 --> 07:47.350
So value face and head.

07:47.430 --> 07:55.350
Is not in the choice for the affected area and hence guardrail.

07:55.470 --> 08:08.010
Say I prepare Another call against LM by modifying the prompt, which says some of the input doesn't

08:08.010 --> 08:09.970
match to my criteria.

08:10.970 --> 08:13.170
Can you regenerate the output?

08:13.290 --> 08:17.210
And then LM again creates another output model.

08:17.330 --> 08:23.010
As you can see here which matches our defined standards.

08:23.570 --> 08:28.330
And this output is again validated by the guardrail CI framework.

08:28.690 --> 08:30.690
And then can be presented here.

08:40.730 --> 08:49.130
Since this program demonstrates a holistic approach to health care data processing, leveraging AI capabilities

08:49.130 --> 08:57.530
and stringent data validation to ensure accuracy, compliance and integrity in medical record keeping.
