The distinction: valid JSON concerns syntax; schema-constrained output adds an explicit shape and allowed types where supported. Neither proves that the values are factual, authorized or sensible for the business operation.
Define the contract before prompting
A lead handoff might require a route, a list of missing fields and evidence references. Decide which values are allowed and how unknown information is represented. Avoid a generic free-text field that downstream code interprets as an instruction.
Provider support and schema restrictions differ. Check guides such as OpenAI structured outputs and Gemini structured outputs for the actual selected API and model.
Separate three layers of validation
- Syntax: can the response be parsed?
- Structure: are required fields, types and allowed values correct?
- Meaning: do the values match evidence and business rules?
A start date and end date can both be valid date strings while appearing in the wrong order. A route can match an allowed enum while referring to the wrong supplier. Those errors require semantic and operational checks.
A worked inquiry contract
{
"route": "needs_review",
"missing_fields": ["travel_date"],
"budget": null,
"evidence_ids": ["message-17"],
"draft_only": true
}
This is an illustrative data contract, not a complete provider request. The application should verify that the evidence ID belongs to the current authorized inquiry and that the routing state is permitted. The presence of “draft_only” in model output does not itself enforce draft-only operation.
Handle non-success responses explicitly
Plan for refusals, timeouts, incomplete outputs and unsupported schema features. A parser exception should not trigger an unbounded loop. A safety refusal should not be relabelled as a formatting error and sent repeatedly to more permissive routes.
Preserve the original failure category for the operator. If a user must clarify missing information, ask for that information rather than coercing the model to invent a value simply to satisfy a required field.
Keep validation outside generation
Use deterministic code for exact rules and access checks. OWASP's input-validation guidance distinguishes structural and semantic requirements. Apply the same discipline to model-produced data before using it in a database write, email or external tool call.
Test malformed responses, extra fields, unknown identifiers and contradictory values. Keep a regression set across model upgrades. Structured outputs make integration more predictable, but the application remains responsible for deciding whether the proposed result is acceptable and what it is authorized to do.
Researched and published 30 November 2026. Provider capabilities are attributed to official documentation; recommendations and worked examples are editorial analysis. No independent model benchmark or client outcome is claimed. Confirm current access, pricing and terms before implementation.
Build the useful version.
Discuss an AI workflow, knowledge assistant or digital-product brief with Jamil Darwish.
Start a conversation