Schemas, Pydantic, and validation — making the model return real data — step 6 of 9
The model returned a response missing the required email field.
In real code, Ticket.model_validate_json(raw) would raise
ValidationError. Here, the assertion on line 8 raises KeyError
before the assertion can run. Fix the script so it prints the string
missing email instead of crashing.
Use if "email" not in data to check first; if missing, print
missing email and exit. Otherwise, continue.
Expected output:
missing email
The model returned a response missing the required email field.
In real code, Ticket.model_validate_json(raw) would raise
ValidationError. Here, the assertion on line 8 raises KeyError
before the assertion can run. Fix the script so it prints the string
missing email instead of crashing.
Use if "email" not in data to check first; if missing, print
missing email and exit. Otherwise, continue.
Expected output:
missing email
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.