This tutorial masterfully explains how to bridge the gap between unpredictable LLM outputs and robust software engineering using Pydantic. It is an essential guide for anyone looking to build reliable, production-ready AI agents through rigorous data validation.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
4. Pydantic for AI Agents | Pydantic Data Validation | Complete Agentic AI CourseAdded:
Hello everyone, my name is Papia Hamemed and you are welcome to my YouTube channel. So guys, we are continuing with our uh complete agentic AI course playlist and in our previous video we have already understood about the asynchronous programming for AI agents why asynchronous programming is required and how it helps us to run the multi- aents protocol.
So in this video I'm going to discuss another very important topic especially whenever you are creating any kinds of AI agents application. Uh the terms is pentic. Okay. So first of all I will give you the idea why this pentic is required and uh without pentic what would be the problem then we'll try to understand the entire pyic concept. So this is my promise of uh if you complete the entire video guys I think you should not be having any kinds of uh doubt related uh pentic whether you are working in uh AI agents whether you are working with any other let's say uh AI application development because everywhere nowadays we use this particular pentic concept okay for the data validation so I think you already know that uh in python all of the variable is uh dynamic variable. Uh basically we uh use the dynamic concept here that means uh here we don't mention any uh data type okay of a variable. Let's say if I'm creating a variable named um a and inside that if I'm storing uh let's say one integer value which is four you can u actually um remove that four and you can also store any other data type let's say string flo or boolean any kinds of data type in the same variable itself okay without uh actually mentioning the data type okay so that's how python works uh it works actually dynamically everything in short any other programming language uh we use the static approach. So there we uh first of all mention the data type then we uh create the variable and stores the data but in Python actually everything works uh as a dynamically. So here you don't need to mention the data types or any kinds of let's say uh hints related that right. So guys to make you understand what I'm going to do. I'm going to open my computer screen and there I'm going to discuss each and everything related uh to this pientic.
So guys uh here you can see um I'm inside my computer screen. So first of all I have mentioned the pyentic uh definition like what exactly the pyic is. So as you can see Pentic is the most widely used data validation and uh settings management library for Python utilizing type hints to ensure data structure integrity. As you can see it validates parts data at runtime to match specified types making it essential for building robust APIs and handling external data with it uh with its core logic written in Rust for high performance.
So this is the definition of pientic. Um basically we use this pientic for the uh data validation. Uh I'm going to u tell you about more uh more about this data validation. What is data validation? why it is required and u I mean how it actually uh solves one amazing problem actually uh whenever we try to create any kinds of end to end application uh especially whenever you are working inside AI domain if you're working in machine learning deep learning uh generative AI agentic AI anywhere uh whenever you are developing the application uh you have to use this pientic okay now here I have listed down some key features and benefit of the pientic as you can see Here are some key features and benefit. So for data validation and parsing we use this pentic. Uh so here you can see defines how data should be structured using standard Python types automatically enforcing the uh these rules. uh basically see uh inside aentic why it is required because here we'll be working with the large lang based model and you know that large lang based model u always will give you the output in unstructured manner and if I want to get a structured output if I want to get the relevant response only that time this pentic data validation is required and whenever we are also passing any kinds of input prompt okay we have to also make it structured so that uh I can get uh the efficient response from my large bank based model. Okay, instead of giving some unstructured data as an input, then uh for the type uh hint and integration, so uses Python uh type annotations to define schemas reducing uh the needs for verbose validation code. Then definitely for the fast performance uh we will be using that uh basically it is written in Rust actually language that's why it is extremely fast. Then strict and lax mode is available inside this pyic. Okay, basically uh here you can um uh do the uh enforcing strict type and you can also perform the um you can also performing this uh lax mode. Okay, for converting let's say uh any other data type to another data type. Okay, this is also possible here. Then uh clear error handling. Okay, provides detail errors when the data validation fails. and JSON schema generation. Pyic models can easily generate JSON schema for documentations or validation uh in other languages. Okay. Now it is telling pyic models. What is this pyntic model? I'm going to tell you. So this is nothing but a class. Okay. We create a class uh and we inherit with this with this pyic actually bas model. Okay. So that's why we call it as a pyic models. So whenever I'm going to show you the practical that time it would be more clear. Okay. So first of all uh let's try to understand the problem okay problem without this pentic if I'm not using pyntentic so what will happen and what would be the issue actually we'll be having okay then I'll try to use the pidentic and uh I'm going to show you the benefit itself so for this I'm going to turn off my camera window guys so that you can see the entire screen uh you don't miss any kinds of code snippet okay whatever I'm going to write I think that would be good for you so guys whenever we are working with any kinds of application whether it's related MLDDL or aentki it doesn't matter uh we will be working with the data for sure right so let's say here I'm going to uh take one example I'm going to let's say create a function I'm going to name it as u let's say um let's say add or let's say uh add patient data.
Okay. So this is my function. So basically this will take the name of the patient and age of the patient. Okay. Um now what I'm going to do let's say this function uh add this informations to the database that means the hospital database. But as of now uh I'm giving you the demo. So here I don't have any kinds of database. So simply what I'm going to do I'm going to print uh those uh variable here. Okay. So let's say I'm going to print the name and I'm also going to print the age. Okay. So once it is done maybe I can give you a message called um data addit successfully. Okay. So let's say this is my message. Okay. Once let's I will call this function. It will add this informations to the database. And here I will get a message. Let's say database um data added successfully to the database. Okay. Let's say this is my masses. Now let's say if I execute this code uh let me take some cell. So if I want to let's say um insert the data first of all I have to call this function add patient data. So inside that let's say I'm going to give the patient name. Let's say I'm going to give BP and age is 25. Okay. Now let's say if I just execute the code, you will see that BP and the age has successfully added to the database. That means it's working fine. Okay. Now let's say this code is written by the senior programmer and uh he has given this code to the junior programmer. He told like okay this is the function and this function you can use for adding any kinds of uh let's say patient informations to the hospital database. Okay. Now what junior programmer will do definitely you will see the like um uh function definition.
So you can see this function definition is that uh this function takes uh two argument. One is the name and another is the age. And the data type is any. That means you can pass any kinds of data type here because here I haven't strictly mentioned you have to pass uh string or you have to pass integer float okay this kinds of uh let's say type hinting I haven't done so what he will do he will try to add any kinds of data here okay maybe let's say um he has given bi here patient um let's say name now he can also give the age like that let's say instead of 25 like that he will write like that 25 okay 25 in string Now if I execute this code still see my data is added to the database but whenever let's say senior programmer is trying to fetch this data. Okay let's say there is another function that function fetch the data. So whenever let's say he's fetching the data let's say he wants to uh he wants to filter out those patient u the patient age is above 25. Okay. So what you will do you will let's say write a condition if uh patient okay if patient age is uh let's say greater than greater than 25 okay 25 then he will try to let's say call those patient okay he has tried to call those patient now just try to see here my junior programmer programmer has added the patient information like that in a string format 25 but again senior program is trying to filter out the patient informations by the integer data type okay definitely this kinds of uh I mean filter I can't ever perform on my database if you're using SQL I think you know that you can't do that because here it is a string type here you are um giving the integer type so definitely this patient will be missed that time okay not only this patient uh I mean similar kinds of if you're doing the same thing instead of giving the integer if you're giving the uh string type that time patient will definitely missed out okay for the filter operation so this is the like problem now you can tell okay then I can easily solve this problem so what I can do maybe uh instead of uh giving it like that so what I will do let's say I'll try to maybe add a condition here so simply here I'll add a condition so If type first of all I'll check the type if type of name is equal equal okay equal equal string str and type of age is integer okay then I'm going to um sorry then I'm going to insert the informations to the database okay otherwise in the else condition I'm going to give a error ES okay so I'm going to raise exception raise let's say type error type error so here I'm going to tell uh invalid data type for the name and age name should be string and s should be in the integer format okay now let's say if I execute this code and now let's say if I am trying to add right now uh this kinds of things. Okay. So what will happen? Okay. One more thing I have to add which is uh the hinting type hinting. So name variable should be string and age as variable should be integer. Now if I execute now see if junior programmer comes here and he uh if he sees see the uh let's say function definition he will be able to see that okay this function takes two argument.
One is name should be string and s should be integer. Okay. So let's say if I give integer data right now let's say 25 it will work perfectly okay there should not be any kinds of error but if is trying to give like that let's say again 25 so definitely that time one error would be coming here okay now it is working completely fine it's not like that uh you won't be able to do that you will be able to do that now your uh senior programmer will be able to fetch the information very easily because you are following the same data type. Okay, whatever data type your senior programmer expected. Okay, so this is the thing. But the problem is that let's say whenever you will be creating a big application, it's not like that you will be creating a single function. There would be lots of function. Okay. So let's say you want to create another function uh let's say the function name is update information. Okay, update patient information. Instead of add patients, maybe I can add update patient data. Okay, that time again it will take the name and age of the patient. Again you have to check this condition. Okay, you have to check this condition whether name is a string and age type is integer. Then you will allow to update. Okay, let's say here I can tell um update uh update uh let me accept this uh data updated successfully in the database otherwise what I will do I'll just try to raise the invalid uh let's say array but uh whenever we be creating the real application it's not like that we'll be working with uh two to three input data there would be lots of data and for all the data I have to write this particular condition okay so again this is a manual task we have to do and how many function you'll be creating in every function you have to definitely check that okay you have to definitely check that let's say another condition comes up the condition is uh condition is let's say um yeah definitely let's say you have given your data type it should be name should be string and it should be integer it's completely fine but let's say your junior programmer insert the data like that let's say instead of giving uh positive 25 he will be giving negative - 255 Five. Now h can't cannot be never never negative, right? H cannot uh uh I mean it should not be negative. But if I let's say add this negative number again it will be adding this particular number successfully. Okay. But this is another issue definitely right now you can tell me okay then what I can do maybe I can uh add another condition here.
So what I will do let's say uh here maybe I will add another condition inside this in uh add patient data. So here I'm going to check another condition. If the age is uh uh if age is greater than okay um age is greater than equal um zero that time I will allow this condition.
Okay I will allow this condition otherwise I will raise another exception h cannot be negative. Okay. And this uh um uh this uh already I'm checking this information whether it is a string or integer. Okay. So this is the else block for this particular if and this is the else block for this particular if. Okay.
Now here I have written the multi- uh conditional statement. So here also you have to do the same thing. Okay. Here also you have to do the same thing.
Okay. So so I'll remove this part.
Okay. Here also you have to add the same thing. Now if I execute this code now see now it will um check that and it will raise the value um value error that means h cannot be negative but if I'm passing the positive that time it will be working there should not be any kinds of problem okay but every time whenever the condition is changing okay uh because it's it is true right whenever you are creating a application your application should handle this kinds of scenario because as a user I can pass anything right um I can pass anything I can pass negative number I can pass string number anything I can pass in your application but your application should uh handle this this kinds of scenario your application should validate the data I'm passing whether it is validate or not okay so either you can do this validation by writing this kinds of manual conditional statement either you can use the pientic one okay pentic data validator so how to use pyntic I'm going to tell you but I I was just showing you the problem. What would be the problem if you're using this uh like traditional approach, traditional conditional approach. So here you have to write this kinds of condition manually every time. Okay. And again if you're creating any other function again you have to rewrite the code and your code size would be very big that time.
Okay. So this is the problem. Now let's try to see how to use this pentic to solve this problem. Now here I have already written how to use the pyentic.
So in pentic first of all we'll define a pyntic model that represents the ideal schema of a data. Now what is model?
Okay model means model means this is a class. Okay. Here we'll try to define a class of pentic. Basically we'll try to uh inherit with the pentic based model.
Okay. After that we'll try to define the schema here. Okay. We'll try to define the schema. Now what is schema? I'll tell you. uh then uh the second thing uh in uh instantiate u model with raw input uh usually a dictionary or JSON like structure. So once my uh let's say pyntic models is pentic class is ready.
I will prepare my data. Okay. I will prepare my input data in uh in a dictionary. It should be uh definitely in a dictionary or JSON like format. Uh then uh we'll try to pass the validated u model object to the functions uh functions.
Um okay here I missed one thing. uh see here basically what we will do pentic will automatically validate the data uh whether it is correct format or not the data we are passing if does not meets the model requirement pentic raises the validation error okay then once let's say my uh data validation meets it is uh let's say validated successfully that time uh it will try to I will try to pass the validated uh model objects to the function the function we have created okay for any kinds of logic let's say for database insertion or update database insertion we can pass to that particular function and our code will be working. Okay. Now this thing we'll try to see in a practical manner.
So for this uh first of all you have to install the pyentic inside your environment. So how to install pyic maybe in the requirement.txt txt you can mention the pyntic package and definitely you just try to take pyic uh like more than one that means uh it should be pentic two version because in two function there are lots of update came but don't use one version because what one version that was older and there you will be getting lots of issue okay I'll try to suggest you use uh this pyic two or more than two okay you can use this one now once you have added in the requirements so simply you can open up your terminal and just write this command pip install hypena requirement.txt. So it will be installing this pyantic inside your environment. Okay. So for me it is already satisfied because initially I already installed this pyic in my environment. So once it is done um this is the notebook guys. I'm also going to share you all of the source code in the description section. From there you can download and you can try in your system.
Now here you definitely select the kernel the environment you are creating.
Just try to select that. So for me I have created this LLM demo. I'll try to select this. Now here I'll be doing the coding example. Now first of all here you have to import this uh pientic based model from pientic. So you have to import like that from pientic. So I'm getting the code suggestion because here I'm using uh this Microsoft copilot. Um yeah so maybe I'll take the suggestion. So from pentic pentic import I'm going to import the base model first of all. Okay. So first of all I'm going to show you the simple example then I'm going to um show you the advanced example of pyentic as well.
Okay first of all let's start with the simple example. Now once it is imported now what I'm going to do guys I'm going to simply write a pyic class. Okay so let's say the class name is patient okay patient data. So let's say this is my class and definitely you have to inherit this particular class with base model. Okay. So this is called actually pentic model. So this becomes actually padentic model. Right? Now inside that you have to define the schema. So schema means like how many data you will be using. Okay. So here I'll be using two data. One is the name other is the age because I'm replicating the same example previously I have given. So here I was considering name and age. Okay. These two information only. And here I have mentioned the name should be in a string and age should be in integer. Okay. Now what I'm going to do, I'm going to again maybe copy the same uh function I created or or let's write that. So div add patient data.
Okay, add patient data. So this was the function previously written.
Okay, but there I passed this name and uh name and uh directly. But here you don't need to give like that. So here what you have to do you have to uh you have to give the uh you have to give the pentic object. Okay. But before that uh let me show you what to do.
So as of now let's uh just pass it. And now the second step we have to uh in uh instantiate the model with the raw input. Uh so we have to prepare our raw input. So input should be in a dictionary or JSON like a structure. So let's try to prepare the input. So input is basically my patient information. So patient patient data is equal to um it should be a dictionary.
First of all I will add the name.
Okay.
Name NH. Okay. So, this is a dictionary format. Now, what I will do, I'll just try to just try to pass uh this particular data to my uh to my where to my pentic object. So, here what is the pentic object? Pentic object is nothing but my patient data. Okay. So, what I'm going to do, I'm going to pass it to the patient data. So here let's try to create um object of patient okay patient let's say this is the um this is patient is equal to um patient data and we'll be passing the data and here I have given two star because this is a dictionary and we have to unpack the value right key and value so that's why we giving Then this uh two uh star here two star means you are unpacking the data. Okay. Now this will become a pyic object. Okay. Now we have created a pentic object. Okay. Now this particular object will be passing to the function. All of the function will be creating here. Whether it's a add patient data, update patient data will be um like passing those informations inside the function. Now right now this function uh can't take the name and a separately. Instead of that it will take what? It will take the patient. Okay, patient object that means the pidentic object. So that means here I can uh make this particular input name is at patient and the type of the patient should be patient data. That means this particular class and this is your pentic model right? This is your pentic class. Now why I have given patient data because inside that I have prepared the schema. That means this add patient data function takes the data.
Okay, take the data and the what is the data format? Data format should be uh definitely there would be a variable called name and name name should be string and there there should be another variable called age. Edge should be integer type. Okay. So that's how we are giving the type. But initially we are giving the data like that. We are giving the name and we are mentioning okay this should be the string. Then we are giving the s this should be the integer. Okay.
But here we're doing the manual stuff.
But here right now we just created a identic class and we're passing this particular class object and it will automatically understand okay what to do what should be the format inside that what should be the structure inside that. This is called actually schema.
Okay schema means the data and the date type of the data. Okay this is called actually schema. Now once it is done now simply here I can add the present information. So simply I can print the information. So right now see I don't I can't actually directly print the name right I can't directly print the name here because we are not taking the name as a name variable we are taking as a patient right so we can call like that patient dot name because inside this particular patient data object we'll be having the variable name okay now we'll do for the same we'll do for the age also so print patient edge okay now once it is done I'll tell data inserted successfully to the database So similar wise I'll create for the update.
I'll create for the update. So let's make it as update.
Okay. Now it will again take the same patient uh uh patient data object that means the pentic object and once it is done we'll try to tell data updated successfully in the database. Okay. And everything will remain same. Now let's try to see whether it is working or not. Now simply what I will do first of all let's say I will add the patient data okay add the patient data so inside this add patient you have to pass this patient information okay patient because this is my pentic object we already created with the help of this pentic class now we'll try to pass it there now see bp uh 25 data added successfully to the database now let's say I want to update the data simply I'll call the update patient data inside that I will again pass the patient object. Now see the patient information is already updated. Now let's say in updated okay so what I can do instead of patient uh I can give patient one let's say you can create multiple patient that time uh you can do that okay patient one patient two like that you can do so let's say this is the patient one information okay this is patient one information this is updated okay so whenever you are doing the update operation so make sure you are giving any other name so simply what I can do see before giving to the update function first of all you have to validate with the help of pidentic so let's say now name is equal to Alex uh let's say this is patient two we are um we are giving this particular raw data to the pentic okay pentic object because here I already told you inst uh instantiate the model with the raw input data so we are initiating the model okay the pentic model with the raw data. The raw data we are passing here. Okay, raw data we are passing here and this is uh doing the validation. If everything is fine uh it will tell okay you can continue then we are giving to the function. Now see this function is working fine. Okay it should be patient two not patient one it should be patient two. Now see now it's become Alex. Okay.
Now the things I want to show you the benefit actually uh using this pentic which is that let's say uh by mistake you have given um let's say string 25.
Okay you have given string 25 instead of giving uh 25. So now what we will do let's say if I execute the code see pyic will not give you any kinds of exception. Instead of that what it will do it will try to convert this string 25 to integer. Okay. So you don't need to do it manually. So by default uh actually internally this pyantic will handle this kinds of scenario. So this will try to convert to the um integer type. Okay, you don't need to manually do that. So here also you can do the same thing. Let's say if I give string 25, your data should be updated successfully. Okay. Now let's say in future you want to add any other information. So you don't need to update these at the code that time. Okay.
Manually. So here let's say you want to add the weight uh weight for the patient. Okay. So let's say weight usually I can mention with the help of float data type because weight should be float. Now simply what I can do I can also print the weight here.
Okay. Now here also I can do the same thing. I can update the weight. And here you can give the weight information right. Let's say weight is uh 70.5 kg.
Now if I add the information see still it will be working. Okay, I'm getting one error because whenever I'm updating the information here, I haven't passed the weight. I have to pass the weight here. Now see, it will work successfully. Okay, so there should not be any kinds of problem. Okay, but in our previous example, you'll see that every time I have to handle this kinds of scenario manually. But in pyentic, we don't need to handle that. Okay, we'll try to just prepare a pyic class and in this particular class, we'll try to handle each and everything for me. Okay.
But you have to make sure whenever you are giving your raw data, try to first of all validate. Okay. Try to first of all validate with uh your pyic then try to pass to the main function. Now I think this particular concept will be clear enough the strict and lax mode. So basically what it do it attempts uh to uh co uh qu cos the data example converting uh this string one to integer one. That means automatically try to convert for you. Okay. But if you want to raise the exception, you can also do that. Okay. Everything is possible here.
And one more thing I want to show you.
Now, let's say if you want to add um any other type data, let's say instead of giving this uh uh let's say this is this is a number. Okay. Now let's say you are not giving the number, you are giving like that 70.
Okay. Say 70.
Okay. 70. Now see if I execute it will throw you the error. Okay, it will tell input should be a valid number. Unable to parse the string to a number because we can't convert this uh this text to the number, right? This is not a number.
This is a other text. This is a like kinds of word we are passing. Okay. But it should be a number. Whether you are giving as a string or integer doesn't matter. It should be as a number. So if you're giving as a number that time it will be able to convert it to the integer. Okay. But if you're giving completely text type it will not allow that time. Okay. So yeah that's how the things work. But this is a very uh basic type example I have given. Now we'll try to move to the advance of this pentic. I will try to see like more depth validation how it can be done. We can add so many parameters so many stuff here. we can add so many let's say um verification and we can uh make it like more powerful. So guys so far we have seen a very easy example uh of the pentic. Now we'll try to make it uh slight complex. Okay. Uh so what I'm going to do maybe I can copy the same uh same class.
So this is the class. So I'll copy this or I can copy the entire code and I will paste it here. Okay. Now see here what I'm going to do instead of taking name age and weight maybe I'll take some more uh extra variable. Let's say here I'll take um another uh another data called married.
Okay. Whether this patient is married or not.
married. So this should be a boolean um data type because either patient should be married if married it should be yes either no. So if yes or no comes into picture so we can consider in boolean type data type then I can take another um data which is allergies. Okay whether patient is having allergies or not. Okay if he or she is having allergies. So what kinds of allergies uh he or she is having? See allergies is is it's not a single let's say type. Okay, there should be multiple types. Someone got allergies from let's say dust. Someone will be getting allergies from any kinds of food, right? It should be different different let's say type. So that's why we'll be taking as a list. Now you can ask me why I'm taking this particular things as a list. Okay? Because it should be list of allergies. Okay? uh let's say uh one patient will have uh might have multiple allergies okay type or let's say one patient would have only single type okay so instead of taking a single type maybe we can take a list of the type uh I mean list type so that if one patient is having multiple allergies so I can easily store them right but if you're taking list so you don't need to directly um I mean write this list okay if you are I mean writing in that way it should it it won't be working so for is what you have to do you have to import this list from the typing module. So you just need to import list from typing module. So there is a module called typing and in this typing we'll we'll be having all kinds of typing okay inside python. So we are importing the list.
Okay, we're telling we need a list. Now it should be a list. Okay, so here we'll be telling this should be a list type.
Okay, now I can't actually write list like that because see what will happen if I open up my blackboard.
See patient is having allergies. Okay, all allergies is nothing but it's a list. Okay, it's a list. Now the thing is that inside that we have to write the allergist type. Let's say this is dust type and what is dust? Dust is a string right? Now let's say food. Okay food is also a string. Okay. So type cannot be any kinds of number. Okay. It should be a definitely a string type. That's why I'm telling u the list we are creating of the allergies inside the list will be storing a string type data. Okay.
because allergist type should be always a string. So that's how whenever we are creating any application we have to think about the data type what should be the data type okay uh the data we are getting what should be the type okay you have to think about in that way so allergies should be list and inside list the data we'll be storing it should be string okay that's why we can uh write this particular syntax and this is called schema okay we are creating the schema right now and we are extending this particular pentic model I think you get it right now I'll add another let's say data which is contact okay contact information. So contact information let's say I want to keep it as a dictionary. Uh let's say someone will pass let's say um contact information like that. Uh let's say um he or she will be writing in that way. Let me tell you.
So contact we want to take it in that way. Let's say contact info is equal to it should be a dictionary. So inside that first of all user will pass the email address. Okay. So let's say this is the email address.
Okay. And this is my phone number.
Okay. Phone number. Let's say this is my phone number like that. Okay. I think you are getting and this should be also string type data. Okay. So that's why uh I'll be taking this contact info as a dictionary. Now inside this dictionary uh I'm going to mention okay I'm going to mention what kinds of data I want to take dictionary should be string type okay key should be also string value should be also string okay that's why we're mentioning the data type and this is a dict and again I can't use the python uh default dictionary function I have to import from this typing So simply I'm going to import this dict.
And now I'll mention it here. Okay, that's it. Now let's try to um execute.
But before executing I think you have to know we have to prepare the raw data.
Now let's try to prepare the raw data.
So we are already getting the suggestion. We'll accept that. So here you can see we have added uh we have added uh this uh one married. Yeah, married. So, this is we have added this is true.
Uh you can also give it as a string. You can also give it as a boolean. It doesn't matter. It will work. Then uh you can uh see we are giving the allergies. So allergies we are giving as a list. As you can see we are having an um allergies from peanuts and selffish.
Okay. Then uh we are giving the contact info. Let's say this is my email address and this is the phone number. Okay. Now let's try to execute uh whether uh it is able to work or not. See I'm not going to update uh these are the function. You can if you want you can also update with all of these variable. You can print all of them but uh let's do it quickly. So here I'm going to do I'm going to simply execute. Okay. Now see uh information is added successfully. That means it's working fine right now. But in some case let's say if I am giving instead of let's say uh this u allergies instead of giving this string if I'm giving any kinds of integer number let's say 23 okay it will give you the error okay it will tell one validation error from this patient data that means the pentic model so allergies it is coming from the allergies okay allergies field input should be a valid string not the integer okay so that's So you can specify this one. So I'll come here again. I'll change it now. Execute. See it will work perfectly. Okay. So that's how any okay any kinds of type you can mention inside your pentic model. Okay. Any kinds of speak uh schema you can mention inside your pyic model. Everything is possible here. Okay. So guys uh we have seen um another example. uh now I'm going to talk about uh this required and optional fields. Okay, what is this required and op optional fields? Let's try to understand. See whenever we are creating this schema right we are creating this pentic model uh that time uh whatever data we are taking right whatever data we are uh let's whatever schema we are um writing we have to give all of this field right we have to give all of this field whenever we are preparing the raw data so if you skip any of them okay so if you skip any of them what will happen so let me show you the example I'll copy this code I'll add it here let's say these are my schema right let's say I I I will let's say um I will let's say um not provide this allergies. So what will happen? So if I remove the allergies from here, let's say I will completely delete this allergy field.
Okay, I'll delete this. Now if I execute it will throw you an error. Okay, it will tell one validation error from uh patient data allergies field required.
Okay, but you haven't given this particular data. So this is the issue.
Okay. Now let's say uh I want to make it as optional. Let's say if user is not also giving this allergy, it's completely fine. It should be completely optional. That means my code will still execute. So for this what I can do? I can make it optional. So to make it optional, simply you have to import optional from typing. Okay, optional from typing and you have to pass this data type inside the optional.
Okay, inside the optional.
And one more thing you have to define which is one default value which is none. Okay. So I'm getting one error.
Let me check.
Okay. The error I'm getting it should not be parenthesis. It should be this square bracket. That's why that error was coming. Now it's fine. Okay. Now this allergies uh field should be optional. If you are also not giving it's completely fine. uh um I mean it will still work and by default this allergies uh field uh will get one value which is none. I can show you by printing that. So what I can do I can print it.
So just for simplicity let let's remove this function. Okay I'll only keep one function. So here I'll just try to print patient dot allergies.
Okay. Now if I see show you my data there uh there I already removed this allergist field. Now if I still execute it will work and you can see this allergies parameter is getting none.
Okay, this is getting none because the default uh default value I have set as none. Okay and it is completely optional. If you give also it will work.
Okay, if you skip it, it will also work.
Now let's say if I give this value so after married I think I'll copy from my previous example this special data and I'll pass it here.
Okay. Now here I have given this allergies field. Now if I execute still it will work but now it will take the value because we have given the value itself. Okay. But if you don't give it still it will work but it will take as a none. Okay. Now one more thing I told you about the default value. See you can also set the default value to any kinds of field. Let's say in the married one I can set any kind of default value. Okay.
Let's say if user is not giving any kinds of value still it will take the default value. Let's say married is equal to by default I will be make it as false. Now if I let's say remove this married field as well still it will work. So that particular okay I can print and show you here I'll print it patient domarit now see by default it is coming as a false okay that means you can also pass any default value if you want. Okay. And you can also make any kinds of field as optional. Okay. This is also possible here. So guys, we have seen the optional and required field. Now I'm going to show you another uh example which is related data validation. So in Pentic, I told you uh we can also perform the data validation if you want. Uh see uh data validation means let's say the data you are giving uh you can also validate whether it is in same uh format or same let's say it follows the same uh same structure or not. Okay. So for an example, I'm going to uh let's say take one example.
I'll copy the same code. So this is like becoming big lines. So what I can do maybe I can just press an enter just to make it as a little bit shorter.
Okay. So what I'm going to do I'm going to take another variable called email. Okay. As of now let's try to consider um I'm also taking one informations from the patient. Uh that means his email and here I'm going to remove the email.
Okay. So in contact information let's only I'm going to take his phone number.
Okay. This is fine for us. Uh so email I'm going to take it as separately. So what I can do you can tell me okay I can make it maybe string because email usually would be any kinds of string type data yes or no right but if I'm taking as a string type data so what will happen let me show you so let's say I'm taking as a string type data email and now uh after name I have to pass the email so let's say email okay email should be email so this should H.
Okay. So let's say BP at the rate example.com or let's say B at the rate uh gmail.com. Okay. Let's say this is my email. It's completely fine. Okay. Now let's see if I execute it will work. See it is working fine. There is no error.
Okay. But let's say if I not giving this add the red sign. Now if I still let's execute my code, it will be working.
Okay, although this email format is not good. Okay, although this email format is not correct but still my uh code is working. Okay, then what is the use of that? So here actually data validation comes into picture. So basically see if I am doing manually with the help of Python. So you can tell me okay I can use regular expression library and I can validate whether this email it is correct or not. Okay, I think you know with help of regular expression also we can handle this scenario but we are using the pyic. Okay, and definitely we are using it for my benefit. Right. So in pentic instead of giving this email as a string you can also give this particular format um to the email format. Okay. So inside this pyic we're having another function called email string email str. Okay. So what this email list here does it does the data validation that means it will automatically check whether you are what kinds of email you are giving it is in correct format or not. If it is not correct format that that time it will throw you the error. Okay. Now instead of giving this uh string maybe I can give this email list here. Now what will happen now? See if I execute this code if I execute this code it will throw you error. The error should be uh this email. Okay value is not valid email address. Now unless and until I'm not giving the valid email address let's say if I give this at the red sign right now now it will work perfectly okay there should not be any kinds of issue so that's how you can perform the data validation before giving the data you can validate whether data we are passing it is it is um incorrect format or not it is validated or not okay I think you get now similar uh um similar things you can do with another let's say data validator uh the name of the data validator is like any URL URL. Okay. Any URL actually validates any kinds of um let's say web URL. The web URL you are passing whether it is uh in correct format or not. So let's say uh I'm also giving the patient uh LinkedIn information. Okay. So let's say this is uh this is a IT uh IT patient hospital.
We are only taking the IT IT patients okay it background related patients and we are also taking their LinkedIn profile okay to our database. So, what I'm going to do, maybe I can create another field here. I'm going to name it as LinkedIn.
Uh, LinkedIn.
Okay.
LinkedIn URL.
Um, yeah. And the type should be any URL because this should be a URL format, right? Any URL. Now, here what I'm going to do, I'm going to pass a URL, LinkedIn URL. So I'm already getting a suggestion.
So maybe I can hit another enter.
Okay. So here we are taking the URL as you can see w https uh/ww um dot uh or let's say I will copy my LinkedIn profile. So this is my LinkedIn profile.
Uh I will add it here.
Okay. Now see if I execute this will this thing will work fine. Okay. There should not be any error. But let's say if I'm not giving this https. Okay. If I'm only giving this ww or let's I'm also removing this ww. Okay. Now if I execute see it will give you the error.
It is telling input should be a valid URL. Okay. Otherwise it should not be working. So this is the work of data validator. Okay. That's how in ping pentic there are some default validator.
um validator uh are present uh you can simply see the documentation and you can do the validation okay if you want this is possible here now one more thing I will show you which is uh let's say uh here we used uh some of the um I mean already available uh data validator um validator like email uh email string then any URL okay but let's in some cases uh there should be some of the data uh and for those data these kinds of validator won't be available. Okay, that time how you can actually validate those data. Let's say uh here what I can do I can show you one example. Let's say here the name we are passing um I want to make a restriction and the maximum length of a name should not be more than uh 50 character. Okay, that time how I'm going to do this kinds of validation.
Okay. So for this we can use the custom um custom validator and we can write this custom validator with the help of one uh one amazing actually function called field. So what you can do uh you can simply import this field from pentic.
So you have to import this field from pentic.
Just a minute. Yeah you have to import this field from pentic. Now here simply you just need to define this. Okay, let's say name that should be string and here I'm going to write the field.
Okay, field inside the field I'm going to tell the maximum length of a name should uh should be only 50 character.
Okay, it should not be above 50 character. Okay. Now let's say if I execute my code, it will work fine completely because right now the name I'm using it is less than 50 character.
But if you increase it, let's say I will add something big.
Okay. Now if I execute, you'll see that it will throw an error. The string should be have most um 50 character.
Okay. So that's how you can do the data validation uh in your custom data if you want. So like that I can also let's say set to any another field. Let's say I want to restrict the age uh age field here. I want uh whatever age uh user is passing. It should be it should be greater than zero and uh lesser than actually let's say 100. Okay. So for this what I can do I can add another field here. uh I'm going to write is equal to field. So there is a parameter called GT. Okay, GT means greater than greater than zero. And there is another parameter called uh LT. Okay, LT means lesser than. So here I'm going to tell let's say 100. Okay. Now if let's say user is giving the age let's say minus 25. So this is definitely lesser than zero. So that time it will give you the error because input should be greater than zero but we are giving uh lesser than zero. Okay. Now if we are giving the correct information it is working fine. Okay. Like that we can also let's say add this kinds of validator inside our allergies. Okay. Let's say this is the list of the allergies we are taking and all all of the values should be string.
Now we can also define the field here.
So I'm going to write the field.
Okay field. uh so here let's say the allergies uh we are taking uh from the user so only uh user can pass actually let's say maximum five five allergies okay five allergy list so that time I can define the max length should be five okay now let's say if user is giving more than that okay allergies I make it as a optional so what I can do I can Maybe add the data here. Previously I had the alerts.
Maybe I can copy H. So from here I can copy.
Okay. So here I can add it. After married I can add the allergies.
Married also I removed right previously.
Okay. Because this was optional. So here I can add the allergies.
There should be a comma. Now if you're giving more value here.
Okay that time it will throw you error.
Okay. because it should be five item but we are giving more than five. Okay. So this is another issue. So let me yeah now it's working fine. Okay so that's how guys we can uh set our custom data uh validator. Okay we can set with that of this field. Now this field you can also use for another purpose uh to add some other metadata. Okay to add some other informations about the schema about the pentic model. Okay, I'm going to show you.
So guys, now let's try to understand um apart from this um um data validation uh like custom data validation. Okay, where we can use this field. Okay, so see field we can also use for the metadata information. Let's say whenever we are creating the schema, you can also pass any kinds of metadata here. Okay, other informations like description. Okay. Uh some other example you can provide here so that whenever this code is using any other programmer or let's say other let's say uh other person they can easily understand what this field does. Okay they can easily understand. Now see the way we have written right now this is completely fine but it does it doesn't have any kinds of information about the name let's say what name does but if I add some other metadata like description and all by reading the description I think other person will easily understand what to do right so for this here I have uh given another demo I have already written this particular demo so see here if you want to write any kinds of metadata metadata um inside your um schema that time you can use this particular field uh function but with that you have to use another function called annotated.
Okay, so you have to import this annotated from typing. So now you have to write the syntax like that. Okay, previously I was writing like that.
Okay, I was directly giving the string field and all but right now if you want to write the metadata first of all you have to give the annotated object. Then inside that you have to define the data type. Okay, the type int let's say this is a string. Then you will be giving the field. So here my field was like maximum length 50. Now here I can pass some other metadata like name or like the title. Okay. So name of the patient. So the uh that means this particular name field is nothing but it's a name of the patient and you can also give the description. Okay. What this does this give the name of the patient in less than 50 character. Then you can also provide some example. Okay. So that by seeing this particular example your programmer can understand okay this actually works like that. So here I've given example like B and Alex. So this is less than 50 characters. Okay. So similar wise you can uh use this for all the field you are having. Let's say I have given some other example. I have added this inside the weight. Okay. The same uh see here we mentioned like this is flo here we have given the field.
Okay. Right now I'm going to remove this trick parameter. I'm going to tell you why this is required. Now here you can also provide the description. Okay.
Uh description and all everything can be done. Okay. So this should be mentioned inside field variable. So here you can mention like description okay weightight of the patient in kg then married also I have given the same thing annotated then this is boolean type field uh I have given the default value. So see if you want to give the default value. So previously how I was giving I was giving like that let's say I was just giving a equal sign and giving the value but right now you're using this field. So inside field itself you can give the default value. Let's say in default is equal to none. So by default it will take as a none. Let's say if you're giving any other let's say true false it will take as true false. Okay. Now here I have given the description. Okay. Now for allergies also you can do the same thing. You can mention like okay this is uh optional because previously this allergies was optional and the data type is list. Uh and inside that we are taking the in uh string type data field is uh default value we are setting as a none. You can also give the default value if you want. and maximum length should be five. Okay. So for contact details also you can do the same thing but I left this part. Okay. Now see if I execute this is giving you an error. The error is uh field required contact details.
Okay. So the error is that here I have written contact details but here I have given contact information. So here you have to give the same name. Same name.
Now if I execute it will be working fine. Okay. Now one more thing I wanted to show you which is this trick parameter. Let's say I told you um in my previous demo I think you remember uh whenever let's say we are giving let's say weight is equal to a string number.
Okay but here what is the type I have mentioned weight is equal to it should be a float number. So by default my pentic is converting this particular string to a float because this is the number okay but always it is not necessary to convert it okay automatically convert it. Let's say you are creating an application there you only want to take this kinds of let's say number as a string that time you should not be convert to the float data type that time you can uh write one parameter uh so here you can write a parameter the parameter name is strict okay strict so you have to make it as true okay so if you make it as true so what will happen you have given float type but if you are trying to give this uh string type it will throw show you error. See it is throwing you error. It is telling weight uh should be uh input um it it should be a valid number float type number but we are giving string type. Okay that's why it's not working. So now if I make it as float okay so it will be working right now. So if you're giving integer also again it will throw an error because here I make it as a strict okay strict parameter. So that's how you have all kinds of customiz customizable option inside Pythonic. Whatever you want, you can do everything here. Okay, this is possible.
So guys, uh we have seen some uh data validator uh validation actually strategy how we can do that. Now I'm going to uh discuss about this uh u validator um in advanced level. Uh we call it as a field validator. Okay. So see so far the validation we have done uh this was like the simple validation uh so we used some of the predefined validator and uh we also like uh given some some of the like um custom constraint there okay but let's say uh you have some complex scenario you have to do uh a complete field verification okay so for an example let me uh let me tell you like um the problem statement the problem statement is that let's say um the application we have created um let's say this is a hospital application so basically this stores the patient information okay then it performs the diagnosis to the patients okay now just try to consider this hospital has also connect connection with some of the bank let's say uh u some of the bank it has the connection let's say HDFC bank it has the connection ICICI bank it has the connection Okay. Now what happens if it is having the connection with the banks?
Let's say whatever patients are coming from these are the banks. So they will be getting 50% discount. Okay. They will be getting 50% discount from this particular hospital. And if the patient is not from these are the banks so they have to pay 100% about the money. So this kinds of let's say validation I want to add inside this application. Now how to do that? So definitely this is little bit complicated. So for this I have already created the code as you can see I just copy pasted the same code but what I have done I just redu uh reduced the u I mean some extra coded uh so that you can uh understand easily see what I have done uh the previous uh uh validation I showed you with the help of annotated I removed each and everything I just taken my previous example okay previous this clean example so here you can see this is the cleaned example okay I have taken the name email age weight married, allergies, contract. Okay, these are the things I have taken. Now, let's say I want to check the email here. Okay, I want to check the email here because only I will understand whether this patient uh he's from any bank or not. How I'm going to understand? Because patient will give their email address, right? So, if I'm a like a very uh I mean common person, so I'll give my common email address like at thegmail.com and all right. But if anyone is working in the bank so definitely they will be having uh their bank domain email address okay let's say hdfc.com or icici.com okay like that so email is the best u field I can uh do this kinds of validator so for this what you have to do you have to write a custom function okay so the function name is I have given email validator okay you can give any name but I have given email validator and whenever you are creating this function make sure you have to give two decorator One is the field validator. So field validator you have to import from pentic. So you can see I have imported from pentic. Uh field validator and inside that you have to mention which field you want to validate. So here I will tell I want to validate this email. Make sure the spelling should be same. Okay. Email field should be validated and another decorator you have to give called class method because this is the method of this particular class. That's why this class method. Now this is my function.
So this function takes two argument. One is the class class object itself. Okay.
And this is the value. Value means uh let's say user is giving the email right email address let's say abcdthegmail.com or sdfc.com. Okay. So this is called actually value. So this particular value will come and I have to validate this particular value. Okay. So for this what I have done I created a list uh I named it as valid domains. So here I just listed all of the bank uh let's say domain. Let's say sdfc.com ici.com.
You can also give any other uh bank domain if you want. Then what I'm doing first of all the value I'm getting from the user let's say whatever email user is passing okay I'm just trying to extract this last part okay as you can see let's say if this is the email address I'm extracting this particular part so this code is doing that so I'm splitting with the help of this address then I'm taking the last value that means this particular part then what I'm checking if domain name not in our valid domain that means if particular this domain name is it is not available inside our valid domains that means this is not Uh this is not a a patient from the bank. Okay. This is a common people.
Okay. So that time I'm raising exception not a valid domain. Okay. Otherwise we are returning the value. Simple. Now let's try uh whether it's working or not. See here I have given simple email address buppgmail.com. So definitely it will throw error because uh I'm not from the bank. Uh okay. Still it is working.
Okay. The issue is that uh this should be patient data object. Okay. Not patient. uh this should be patient data object uh patient data class. Now if I execute now see it is giving you error.
It's telling value error not a valid domain. Okay that means uh this particular person it is not from the bank. Now say if I give the bank domain let's say I'll give sdfc.com.
Okay.
Now it should be working.
Still some error.
build required merit.
Okay. So here I haven't passed the married, right? Uh so let's give the married as well.
Married is equal to true. Now if I execute, see it's working fine. Okay. Because this particular person uh he's from the bank itself. Okay. So that's how you can do advanced level uh uh validation. Okay.
This is called field validator. Now you can also do some transformation with the validation as well. Now let's say I will be working on another example.
So one more thing you can do uh with the help of this field validator you can um you can definitely validate but uh if you want you can also do do the transformation. Let's say the name you are getting from the user. Uh you want to store this particular name in a uppercase format always. Okay. If user is also not giving it's completely fine but you want to make it uppercase and you want to u save inside the database.
So for this again you can write another validator uh field validator. So see this is the function I have created called transform name and I told you you have to use two decorator. One is field validator. Now you have to specify which field. I'll tell name field and the class method decorator. Now it will take class object and the value. Now whatever value user is giving that means the name. I'm just doing the upper operation. Okay. And I'm returning it. Now see uh here I'm giving let's say lower case BP. But if I execute this code still you will see that in the database all of the uh character would be in upper case. Okay.
So this is called transformation with the help of this field validator. That is also uh we can do here.
So guys, now we'll understand one another important concept which is model validator. So previously I told you about this field validator. So in field validator uh what uh I was performing.
So let's say if I want to do a single field validation that time I was using this field validator. Okay. But let's say there is a condition you have to verify multiple field. Okay. Multiple field means let's say u the system you have created you want to add another functionality which is let's say if patient age is greater than 60 okay that time in the contact details there should be a emergency number so this kinds of uh validation I want to do okay so that time with the help of only field validator I can't do that because I can't um I can't actually mention two field together in the field validator okay only one field can be mentioned so we solve this particular problem with the help of this model validator So for this this is a very simple concept. So let me show you how to add this. So here you have to add this uh add this code.
So here I'll just try to define the indentation and you have to import this model validator from pi identical. Okay. There is another validator called model validator. You have to import and inside that you have to uh give this parameter as after mode is equal to after. And here you will be creating the function.
The function name is uh validate emergency contract. This will take the class okay and this will take the model.
Model means the entire schema. Okay. So if you give the model that means you can access all of the schema okay uh from inside this particular function. So here you can see here I'm checking if model age that means I'm extracting the age if it is um greater than 60 and uh emergency not in model. Okay, that means if emergency phone number is not available that time you're raising one exception value error patient older than six uh 60 must have a emergency contact. Okay, then we're returning the model. Now let's try to check this whether it's working or not. So let's say right now my age is 25 that means this kinds of uh this condition uh will not match. So it will work fine. So if I execute see it is working fine. There is no error. uh but if I let's say make my age uh to more than 60 let's say 70 now this will throw you error it is telling uh value error patient older than 60 must have emergency contact number now here I have to add the emergency contact number so maybe after the phone number I can add a emergency number now if I execute see it's working fine okay so this is called actually model uh validator so that means if you have multiple uh field verification that time you can use this model validator Okay, inside your application.
Now let's try to understand another concept which is computed uh fields. Now with the help of computed fields, what we can do? Let's try to understand.
Let's say in the same example um I want to do another thing. Let's say um here I have added another informations another data called height.
Okay. Now um see what computed field does it does a computation itself. Okay.
Let's say if user is giving any kinds of information and it has to recreate or let's say generate a completely new information by utilizing the same information that time we'll be using computed fields let's say in this case my patient has given me weight and height but I want to calculate inside my pentic uh the BMI okay BMI of the patient I'm not taking the BMI from the patient itself instead of that what I want with the help of weight and height I want to calculate the BMI so that time I'll be using this computed field. So you have to first of all import this computed field from pi identic. We have already imported. Now you have to again uh use this as a decorator and you have to write a function here. So my function name is BMI and again you have to use another um another actually um uh another uh decorator which is property.
Okay, you have to use this property. Uh so the property I think this is already available.
uh this property is already available inside Python. This is default one. So you don't need to import from anywhere.
Then this is the function we are writing BMI and we are giving the self parameter and this returns uh the float value.
Okay. Because BMI should be float and here we are calculating the BMI. We you can see here we are taking the weight.
Okay. Uh then we are dividing with the help of this height and we are squaring it. Okay. Then we are taking the uh BMI.
Okay. We are calculating this BMI. We are taking the result and this result we are trying to return it. Now if I want to print this so I I have to just simply write patient.bmi right now see BMI I haven't written here okay inside my schema instead of that I'm calculating it and I'm returning it. So that's why I have to call with the help of this particular function. Let's say if this function name is BMI test you have to also give BMI test here. Okay this is required. Now simply let me show you whether it works or not. So here I have already given the height. uh height let's say I'm considering in meter and weight I'm considering in kg. Okay. Now if I execute now see it is also giving you the BMI. Okay. So this is called actually computed field. So if you want to compute anything with uh with the existing uh schema you are having existing data you are having you can use this computed field at time.
So guys now we'll discuss about another important concept inside pentic which is nested model. Uh so sometimes what happens whenever we create the fields um so field might be uh complex field as well. So let me give you one example.
Let's say here I have this particular um pentic model that means the class patient data. So here I'm having the patient information like name, gender, age and another information I have which is address. Okay. Now address field might be complex field because address I can't write in a single uh let's say word. So inside a address there should be three kinds of entity. One is city, pin and state. Okay. Now here I'm not going to write uh this kinds of syntax.
Okay. Because this is not possible here.
So instead of that what we can do we can create another actually pentic um class.
Okay. Pyic model and we can make it as a nested. Okay. Uh so how it can be done?
So let's say here I have created my patient data. This is my model. And here I have created another model which is uh address. Okay. And again I inherited with the help of this base model. Okay.
Now here I've given three entities CT, state and pin. Now first of all I've created the address uh as you can see address dict. So city is equal to I have given gorgal state is equal to harana.
Pin is equal to this is the pin. Okay.
Now this particular address you have to pass where to this address model. Okay.
So we are passing it to the address model. We are unpacking that. Okay. Now this will uh this will return me one pentic object. Okay. Now I'm going to create my patient information right now.
So you can see name uh gender age and now right now address is equal to see what I have done I have given this particular object this class. Okay address should be this class. So I'm passing this particular object right now. Okay address is equal to this address. Then this patient information I'm passing inside my patient uh model.
Okay. Now this is giving you the patient information. Now inside this patient information you are having all of the information whether it is related patient data, whether it is related address. Now let me show you. So here I'm putting first of all all of the patient uh you can see data. So inside patient I am having name age okay and the address. Okay address object is also available. Now if I want to uh let's say access the name I can do that. If I want to access the address I can also do that. Now let's if I want to only access the patient city. So you just need to write patient uh address dot city. So this will give you the city. Okay. So that's how you can write this nested models. This is also possible inside pentic. Okay. I hope you get it.
So guys uh one more last thing I'm going to discuss about this pentic which is uh serialization. That means you can also um export your uh pentic object um as a dictionary or as JSON. For this we use serialization. So I have taken the same example. So only the last part what I have done. So here you can see that say this is my final object uh of my u nested uh nested model. So what I'm doing I'm just doing model.dum. If you do model dump so what will happen? It will return you as a dictionary. See you are exporting your object as a dictionary. Okay, you can see this is a Python dictionary. Okay, but if you're using this uh JSON dump, okay, this should be uh string that means it's a JSON format. Now, you can use uh JSON library to export um I mean you can also export it. You can also dump it and you can also load it um let's say later on.
Okay, this is required. Let's say whenever let's say you have created a pyic object okay you have done some data validation and all and you want to uh take it as a take it as a let's say file and uh let's say you want to load it later on you can do do this kinds of serialization okay this is also possible it's like a like in machine learning we train model right after training the model we save the model right we serialize the model so it's kind of that okay now guys uh with that our discussion has been end understood all of the concept concept related pyntic.
Okay. And I think now you are pretty much comfortable with pyic. You should not be having any kinds of issue with the pyic whether you are working in uh aentic whether you are working in machine learning deep learning anywhere you will see this kinds of concept will be available. Okay. Now one thing I want to show you. So if I go to Google and if I search like why pyentic is important for AI agent. As you can see uh pyntic is crucial for agent because it brings the structure relability and type safety for software engineering to be uh traditionally unstructured and unpredictable word of large language models. Okay. By leveraging the Python typhoons and uh runtime data validation.
Pentic ensures that AI agents interact uh realy with external docs APIs and databases. Okay. So here are some of the uh you can see uh concept they have given. You can go through that. you'll see that uh at the end this particular concept is very much required whenever we're working with aentki application.
Okay. So yes guys I think you have understood all of the concept. If you have liked it please try to subscribe to my channel and share this video with your friends and family. Now we are uh pretty much ready for exploring all kinds of orchestrator framework. uh so uh now uh like going forward we'll be exploring the uh uh this orchestration framework like all of the agentic AI framework we'll be uh exploring the langraph we'll be exploring the uh crei we'll be exploring the autogen okay all of the framework we'll try to explore one by one even we'll be also exploring the non non-code platform as well like n so there uh these kinds of concept will definitely come so that time um I think you should not be uh confused okay that's why I have clarified each and everything so yes guys this is all about uh from this session. Uh thank you so much for watching this. I'll see you in the next video guys. Thank you.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











