Skip to content

Instantly share code, notes, and snippets.

@pmbrull
Created March 14, 2022 19:26
Show Gist options
  • Save pmbrull/cc31a2cfea677bf70a487d09c2df774e to your computer and use it in GitHub Desktop.
Save pmbrull/cc31a2cfea677bf70a487d09c2df774e to your computer and use it in GitHub Desktop.
How to make the most of Pydantic 03
from pydantic import ValidationError
bad_data = {
"name": "Lévy",
"age": "am I an age?", # Note the type change here
"address": {
"city": "Wonderland",
"zip_code": "ABCDE",
"number": 123
}
}
try:
CatRequest.parse_obj(bad_data)
except ValidationError as err:
print("Something went wrong with the data!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment