Structured output
Structured output constrains an answer to a shape such as a JSON schema. Correct structure and correct meaning are separate requirements.
Before you start: Review Few-shot first. Python-like examples use variables, lists and functions.
Follow the mechanism
Contract
Define required types and allowed values.
Start with an everyday explanation
A form can insist that every box is filled correctly while still containing a false address. Shape checks are necessary but cannot establish the facts.
See a concrete example
A schema allows approve, reject and needs_review. A record marked lapsed can still receive an invalid semantic approve even though the enum is legal.
A claim to question
Schema-conforming output is not evidence of truth, permission or successful execution.
Try before revealing the answer
Design a schema with decision, evidence_ids and reason. List two checks beyond JSON parsing.
Show the worked answer
Verify every evidence ID belongs to the authorized retrieval set and that the decision agrees with deterministic policy constraints. Bound reason length and reject missing evidence for decisive answers.
Now explain the idea to someone else using your own example. If you cannot explain a stage, revisit it before moving on.
Engineering details and trade-offs
Validate required fields, types, allowed values and limits. Handle refusal, truncation and schema-version differences explicitly.
Perform business checks after parsing. A syntactically valid {decision:approve} must not authorize payment or override verified policy rules.
Reason through the example
A schema allows approve, reject and needs_review. A record marked lapsed can still receive an invalid semantic approve even though the enum is legal.
Implement and test
Design a schema with decision, evidence_ids and reason. List two checks beyond JSON parsing.
Inspect the reasoning and expected result
Verify every evidence ID belongs to the authorized retrieval set and that the decision agrees with deterministic policy constraints. Bound reason length and reject missing evidence for decisive answers.
What to measure
State the expected result before changing a control. Record your inputs, compare the observed result and explain one limit of this model. In a real implementation, test the failure case as well as the normal path.
Answer before reading the reference
What should happen after schema validation fails?
A defensible answer
Return a controlled failure or use bounded repair with the error details and the same authorization rules. Log the failure category and never treat a parse error as business success.
Prepare the follow-up
How would you evolve the schema without breaking consumers?
Show follow-up reasoning
Version the contract, distinguish backward-compatible optional fields from breaking changes and validate consumers against both expected versions. Bound repair attempts and support explicit refusal/error outcomes. Keep semantic and authorization checks after parsing for every version.
Use the engineering explanation and worked task above to support your response. Identify which assumptions you would need to verify in production.
Choose a practice depth
- New to GenAI
- Define structured output with the everyday example and name its key limitation.
- Applied experience
- Explain the example, implementation choice and a measured failure case. Use the exercise as a small design review.
- Senior or systems depth
- Answer the follow-up, compare alternatives and justify an evaluation or rollout plan with operational constraints.
Self-review your answer
0/4 checks selected. This is self-assessment, not an interview score.
Your explanation and revision notes
Loading local notes…