In this article
Structured output constrains representation where supported, while refusal, completion state and the truth of extracted values remain separate application checks.
A JSON-producing application can fail in several ways that look similar to a parser. OpenRouter documents structured output support per endpoint and notes that enforcement varies by provider. A robust consumer therefore checks completion and result type before validating a schema, then assesses whether the values actually satisfy the task.
Choose the correct schema field
Responses places the format request under text.format, while Chat Completions uses response_format with its documented nesting. For a hypothetical document-labeling job, define the allowed label shape and required fields using the selected endpoint’s schema. Do not confuse a request that asks for JSON in prose with a structured-output request. The latter also depends on actual model and provider endpoint support.
Check endpoint support and enforcement
The official page states that support can differ between endpoints serving the same model. It also explains that native strict enforcement, translation and strong-hint behavior are not identical. Use current supported-parameter metadata and required-parameter routing when appropriate. A strict flag should not be presented as a universal guarantee across every backend. The application still validates the received object before allowing it into downstream processing.
Handle refusal and incomplete output explicitly
A refusal is not a successful document label, and a truncated fragment is not a complete JSON object. Inspect the response status and applicable refusal or finish indicators for the chosen API. If the expected generated record is absent, return a distinct application outcome. Do not silently replace it with a default label that looks valid but was never supported by the model’s completed result.
Validate meaning after validating shape
A schema can require a label string without proving the label is correct for the source document. Evaluate representative inputs with known expected behavior. If the task extracts a reference identifier, compare it with the source rather than accepting any schema-valid string. Shape validation protects the consumer’s structure; domain validation protects the decision the product makes using that structure.
Keep repair features in their proper layer
Response healing can help repair malformed JSON in supported non-streaming workflows, but it does not establish truth or replace schema and domain checks. Use it as a formatting aid where documented. The final application outcome should distinguish a valid label, unsupported request, incomplete generation and failed parsing. These explicit branches make failures explainable without turning every nonstandard response into an unexamined retry or an invented successful record.
Documentation and further study
Related engineering guides: Structured output through OpenRouter: when to use a JSON schema; Errors inside an OpenRouter stream: why HTTP 200 is insufficient.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.