- Model-agnostic: Supported on all chat‑capable models on Friendli.
- High schema fidelity: Generates outputs that reliably conform to your provided schemas.
What is Structured Outputs?
Structured Outputs ensures LLMs return predictable, machine‑readable results (e.g., JSON) instead of free‑form text. This is essential for workflows that require validation or downstream automation.Structured Outputs with Friendli
- Schema‑aligned generation: High‑accuracy adherence to your JSON Schema.
- Flexible modes: Choose strict or loose JSON mode, or apply regex constraints as needed.
- OpenAI compatible: Use standard response_formatoptions with OpenAI SDKs.
Structured Outputs Parameters
| Type | Description | Name at OpenAI | 
|---|---|---|
| json_schema | The model returns a JSON object that conforms to the given schema. | Structured Outputs | 
| json_object | The model can return any JSON object. | JSON mode | 
| regex | The model returns a string that conforms to the given regex schema. | N/A | 
Supported JSON schemas
We support all seven standard JSON schema types (null, boolean, number, integer, string, object, array). The supported JSON schema keywords are listed below.
Using unsupported or unexpected JSON schema keywords may result in them being ignored, triggering an error, or causing undefined behavior.
Type-specific keywords
- integer- exclusiveMinimum,- exclusiveMaximum,- minimum,- maximum(Note: these are not supported in- number)
 
- string- pattern
- format- Supported values: uuid,date-time,date,time
 
- Supported values: 
 
- object- properties
- additionalPropertiesis ignored, and is always set to- False.
- required: We support both required and optional properties, but have these limitations:- The sequence of the properties is fixed.
- The first property should be required. If not, the first required property is moved to the first.
 
 
- array- items
- minItems: We support only- 0or- 1for- minItems.
 
Constant values and enumerated values
const and enum only support constant values of null, boolean, number, and string.
Schema composition
We support onlyanyOf for schema composition.
Referencing subschemas
We only support referencing ($ref) to “internal” subschemas. These subschemas must be defined within $defs, and the value of $ref must be a valid URI pointing to a subschema.
Annotations
JSON schema annotations such astitle or description are accepted but ignored.
Simple Example
- json_schema
- json_object
- regex
This example provides a step-by-step guide of how to create a structured output response in JSON format.
We use Python and the 
pydantic library to define a schema for the output in this example.1
Define Object Schema
Define a schema that contains information about a dish.
2
Asking the model for structured output
Call structured output and use schema to structure the response.
3
Using structured output results
You can use the output in the following way.The code output result is as follows.
Result: