Is it possible to load only valid data to a pydantic model?

Viewed 60

I'm trying to migrate input validation from marshmallow to pydantic for data validation as pydantic is used elsewhere in the project. I've got a bit stuck though, as the current code has the option to return only valid data extracted from the marshmallow ValidationError, like this:

try:
    MyMarshmallowSchema().load(payload)
    return payload
except ValidationError as vld_fail:
    return vld_fail.valid_data

Is it possible to do something equivalent with pydantic?

0 Answers
Related