Define schema
fields, types, required
Model generates
with schema in context/config
Parse output
attempt JSON.parse
Validate against schema
types, required fields
Retry on failure
or accept
Most structured-output systems combine two mechanisms: giving the model the schema as part of its instructions (so it knows the target shape) and validating the result programmatically afterward (so you catch the cases where it didn't comply), often with automatic retry using the validation error as feedback.