- 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 FriendliAI
- Schema‑aligned generation: High‑accuracy adherence to your JSON Schema.
- Flexible modes: Select strict or loose JSON mode, or apply regex constraints as needed.
- OpenAI compatible: Use standard
response_formatoptions with OpenAI SDKs.
Structured Outputs Parameters
Supported JSON Schemas
FriendliAI supports all seven standard JSON schema types (null, boolean, number, integer, string, object, array). The supported JSON schema keywords are listed below.
Type-Specific Keywords
integerexclusiveMinimum,exclusiveMaximum,minimum,maximum(Note: these are not supported innumber)
stringpatternformat- Supported values:
uuid,date-time,date,time,uri
- Supported values:
objectpropertiesadditionalPropertiesis ignored, and is always set toFalse.required: FriendliAI supports both required and optional properties, with 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 position.
arrayitemsminItems: FriendliAI supports only0or1forminItems.
Constant Values and Enumerated Values
const and enum only support constant values of null, boolean, number, and string.
Schema Composition
FriendliAI supports onlyanyOf for schema composition.
Referencing Subschemas
FriendliAI supports only references ($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 on how to create a structured output response in JSON format.
This example uses Python and the
pydantic library to define a schema for the output.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: