- Consistent fields: Responses follow the fields defined in your schema.
- Type safety: Values use the data types defined in your schema.
- Simpler parsing and integration: Applications can consume responses without additional format conversion.
The strict-mode rules below apply to
response_format.json_schema.strict: true and tools[].function.strict: true. They do not apply to strict: false or legacy json_object mode.
When using structured outputs with
kimi-k2.7-code, use parsed reasoning. reasoning_format: "raw" is incompatible with json_object and json_schema response formats.Tutorial: Structured Outputs using Cerebras Inference
The following steps define a movie-recommendation schema and use the Cerebras Cloud SDK to return a response that conforms to it.1
Initial setup
Complete steps 1 and 2 of the Quickstart to configure your API key and install the Cerebras Cloud SDK.Import the required modules and initialize the client.
2
Define the schema
Define a JSON schema that specifies the response fields, their types, and which fields are required. This example defines a movie recommendation with a title, director, and year.
3
Use Structured Outputs
Add the schema to Sample output:The returned JSON conforms to the schema and can be used directly by the application.
response_format in the API request.strict: trueuses constrained decoding to guarantee that output conforms to schemas in the supported JSON Schema subset. Recommended for production use.strict: false(or omitted) treats the schema as a hint. The model may return additional fields, miss required fields, or use incorrect types, similar to JSON mode.
Understanding strict mode
For schemas that use the supported JSON Schema subset, strict mode guarantees that generated output conforms to the schema. Setstrict to true to enable constrained decoding at the token level.
Why use strict mode
Without strict mode, a response can contain:- Malformed JSON that fails to parse
- Missing required fields
- Incorrect data types, such as
"16"instead of16 - Fields that are not defined in the schema
- Valid JSON
- Fields that conform to the schema
- Correct data types for properties
- Fewer retries caused by schema violations
Enable strict mode
Setstrict to true in your response_format configuration:
Schema requirements for strict mode
When using strict mode, you must setadditionalProperties: false. This is required for every object in your schema.
Limitations in strict mode
When strict mode is enabled, your schema must conform to specific requirements. See the Supported Schemas section for detailed information on constraints, limits, and unsupported features.Schema references and definitions
Use$ref with $defs to define reusable components within a JSON schema. Reusable definitions reduce repetition and make schemas easier to maintain.
Supported schemas
Structured Outputs supports a subset of JSON Schema. The following sections describe its supported types, properties, and constraints.Supported types
The following types are supported for Structured Outputs:Schema constraints
When using strict mode, the following constraints apply:Required schema structure
All schemas must follow these rules:- Root must be an object: The top-level schema must have
"type": "object". - Root must define properties: Include a
propertiesobject at the root. - Root unions are not supported: The root cannot be an array, scalar, or
anyOfunion. - No additional properties: You must set
"additionalProperties": falsefor every object in your schema. - Arrays need an item schema: Every array must define
itemsor useprefixItemswithitems: false.
These requirements are enforced by API version 2. Non-conforming strict schemas return a validation error. See API Versions.
Supported features
Your schema can include the following JSON Schema features:- Nested structures: Define complex objects with nested properties.
- Required fields: Specify which fields must be present.
- Optional fields: Properties may be omitted from
required. - Enums (value constraints): Use the
enumkeyword to whitelist the exact literals a field may take. Seeratingin the example below. - Constants: Use
constwith primitive string, number, integer, boolean, or null values. - Non-root unions: Use
anyOfbelow the root object. - Schema references: Use local, nonrecursive
$refvalues with$defsto define reusable schema components within your schema. - Tuple validation:
items: falseis supported when used withprefixItemsfor tuple-like arrays. - Number constraints: Use
minimum,maximum,exclusiveMinimum,exclusiveMaximum, andmultipleOfto constrainnumberandintegervalues. - Annotations:
description,title,$schema, anddefaultare accepted but are not enforced by constrained decoding.
Unsupported features
The following JSON Schema features are not supported in strict mode:
Unlisted JSON Schema keywords should be treated as unsupported unless the selected model’s documentation states otherwise. String-length support is model-dependent. In particular, strict tool schemas for
qwen-3.8-27b do not support minLength or maxLength.
Example: Complex schema
The following example defines a schema with nested objects and arrays:Key ordering
The keys in the generated JSON output will appear in the same order as they are defined in your schema.Working with Pydantic and Zod
You can define a schema with Pydantic for Python or Zod for JavaScript instead of writing JSON Schema manually. Pydantic’smodel_json_schema and Zod’s zodToJsonSchema methods generate JSON Schema for use in an API request.
JSON mode
JSON mode generates valid JSON without enforcing a specific schema. The model chooses which fields to include based on the prompt.We recommend using structured outputs with
strict set to true instead of JSON mode whenever possible. Structured outputs guarantee schema adherence, while JSON mode only ensures valid JSON without enforcing a specific structure.response_format parameter to json_object and include instructions in your message asking the model to respond in JSON format:
Structured Outputs vs. JSON mode
The following table compares Structured Outputs and JSON mode:Conclusion
Learn how to combine structured responses with other Cerebras capabilities:- Tool Calling: Connect models to external functions and data.
- Streaming: Process response chunks as they are generated.
- CePO: Improve reasoning with test-time compute.

