Skip to main content
Structured output is a core capability of Model Inference that guarantees the model returns data in a predictable, machine-readable format. By providing a JSON Schema, you constrain the model’s response to match your exact specification.

The problem with unstructured output

Traditional LLM interactions return free-form text:
This creates challenges:
  • Parsing complexity: Must extract the actual classification from prose
  • Inconsistent formats: Response structure varies between calls
  • Error-prone: Regex or string matching can fail on edge cases
  • No type safety: Can’t validate response structure at compile time

How structured output works

With structured output, you define the exact response format:
The model returns exactly what you specify:

Why structured output matters

1. Reliable automation

Structured output enables reliable automation pipelines:

2. Type safety

With TypeScript, you get compile-time type checking:

3. Schema validation

The model is constrained to produce valid JSON matching your schema:
  • Required fields are always present
  • Types match your specification
  • Enum values are restricted to defined options
  • Numeric constraints are enforced

4. Consistent integration

Every response has the same structure, making integration predictable:

How structured output is enforced

Not every model enforces output_format_schema the same way. The platform picks a strategy based on the model’s capabilities, and the response is validated against the schema either way. Both paths return the same structured_output shape, so client code does not need to branch on the model.

Client-side schema validation

After the model responds, the platform validates the payload against your output_format_schema (JSON Schema draft 2019-09). The inference job completes either way — validation just decides which field on the result is populated:
  • Validation passes. structured_output holds the parsed object matching your schema; failed_structured_output is null.
  • Validation fails. structured_output is null and failed_structured_output carries the raw JSON the model emitted along with the validator’s message explaining why it was rejected. The job does not fail, so downstream steps still run — check failed_structured_output before consuming structured_output.
Both fields are mutually exclusive: at most one is populated on any completed job.

Requirements for forced-tool-use models

When you target a forced-tool-use model (Sonnet 5.0 or Opus 4.7 / 4.8), a few extra constraints apply:
  • Top-level additionalProperties: false is required. The forced-tool path rejects a top-level object schema that omits it (or sets it to true) because the reserved final-answer tool needs a closed shape. See the JSON Schema Reference.
  • temperature and top_p are silently dropped. These models reject sampling knobs; the platform strips them from your request rather than failing the job.
  • Strict tool-use caps do not apply. Forced-tool-use models bypass the strict tool use limit, but the reserved tool name nio_emit_structured_output is off-limits — a caller-supplied tool cannot use that name.

JSON Schema capabilities

Model Inference supports standard JSON Schema features:

Basic types

Constraints

Nested structures

Design principles

1. Define what you need

Only include fields your application will use:

2. Use enums for known values

Constrain categorical outputs to valid options:

3. Set appropriate bounds

Define numeric ranges when applicable:

4. Add descriptions

Help the model understand field semantics:

Common patterns

Classification

Extraction

Transformation

Using Structured Output

Practical guide to schema definition

JSON Schema Reference

Supported schema features

Model Inference Overview

How inference works

Running Inference

Submit inference requests