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:| Without Schema | With Schema |
|---|---|
| Parse response text | Direct property access |
| Handle format variations | Consistent structure |
| Runtime validation needed | Schema-enforced validity |
| Type casting required | Native types |
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

