Relative Content

Tag Archive for pydantic

How to make all fields required in pydantic model

I have a pydantic (v2) model containing some fields with default values. I would like on some occasions for these models to be used in a “strict mode” where the default values are no longer available and every field must be supplied when using model_validate.

Pydantic list of lists output model gives error

I get an error {'loc': ('response', 'piegraphdata'), 'msg': 'value is not a valid list', 'type': 'type_error.list'} on running the below code. I tried a number of variations but all give the same error. This is what I currently have:

How to add and retrieve metadata on a pydantic field

I would like to add some metadata to model fields. This is not necessary for validation or serialisation but might be user for data display or perhaps as a hint when entering data.
For instance one might want to add a unit to a field.