Question presented to candidate: "Our ticket-triage feature asks the model for JSON and about one response in fifty breaks the parser or has a field we cannot use. Walk me through how you would make the model's structured output reliable, and what each technique actually guarantees."
What a strong answer should cover:
- The reliability ladder: prompt-only instructions guarantee nothing, JSON mode guarantees syntax only, schema-constrained output (OpenAI Structured Outputs with
strict: true, Anthropicoutput_config.format, GeminiresponseJsonSchema) guarantees the shape, and application validation is still needed for meaning - The mechanism: constrained decoding masks every token that would break the schema before sampling, so invalid output cannot be produced; the schema is compiled to a grammar or automaton, which costs extra latency on the first request with a new schema
- What constrained decoding does not guarantee: refusals, output cut off by the token limit, values that are well-typed but wrong, and (in some providers) exact casing of enum values, so the code still checks the stop reason and validates
- Schema design for accuracy: flat and small, enums for closed sets, every field required with
nullfor "unknown", clear field descriptions, a supported subset of JSON Schema per provider, and putting any short explanation field before the answer field rather than asking for hidden reasoning - The trade-off: strict formats can lower answer quality on reasoning-heavy tasks, so a common pattern is to let the model think first and then emit the structured result, and to measure both validity and accuracy with evals
Clarifying questions expected:
- Which provider and model, and is it an API model or a self-hosted open-weight model (that decides whether native strict mode exists or we add a constrained-decoding engine)?
- Is the output an answer for our code (extraction, classification) or the arguments for an action (a tool call)?
- What happens downstream if a record is wrong: shown to a user, written to a database, or used to move money?
Code / implementation expected: Optional โ a request with a JSON Schema plus a validator on the response, or a sketch of how token masking enforces a schema.