The problem with unstructured output
Traditional LLM interactions return free-form text:- 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: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 enforcesoutput_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 youroutput_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_outputholds the parsed object matching your schema;failed_structured_outputisnull. - Validation fails.
structured_outputisnullandfailed_structured_outputcarries 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 — checkfailed_structured_outputbefore consumingstructured_output.
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: falseis required. The forced-tool path rejects a top-level object schema that omits it (or sets it totrue) because the reserved final-answer tool needs a closed shape. See the JSON Schema Reference. temperatureandtop_pare 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_outputis 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
Related content
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

