Pydantic model (schema definition)
response_format / schema passed to API
Parse + validate
Repair loop on failure
The most common real-world pattern is: define a schema with a validation library, hand it to the model via a structured-output API, and wrap the whole thing in a repair loop for the cases that still slip through.