generateStructured validates the result against a schema and can repair it.
Enforcement modes
Validation-only is the default and is right when a retry is cheap. Repair costs a second
generation when the first is invalid, which is worth it when the call is user-facing and a
failure means showing an error.
The schema
totalPrice gets better results than tp.
Reading the result
When to reach for this
If you are about to write a regex over a model’s reply, you want this instead.
Temperature
Lower it. Structured extraction is not a creative task, and0.1 to 0.3 produces far more
consistent field values than the default.