﻿# Handle OpenRouter structured-output refusals separately from schema parsing

Handle OpenRouter structured-output results by separating JSON shape, refusals, truncation and domain correctness instead of assuming every successful request is a valid record.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-openrouter-json-refusals/
Language: en

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

- [Structured Outputs - Type-Safe JSON Responses from AI Models](https://openrouter.ai/docs/guides/features/structured-outputs).

- [OpenRouter API Reference - Complete Documentation](https://openrouter.ai/docs/api-reference/overview).

- [Provider Routing - Smart Multi-Provider Request Management](https://openrouter.ai/docs/guides/routing/provider-selection).

Related engineering guides: [Structured output through OpenRouter: when to use a JSON schema](/journal/openrouter-json-schema/); [Errors inside an OpenRouter stream: why HTTP 200 is insufficient](/journal/openrouter-stream-errors/).
