Skip to main content
Friendli offers structured outputs capability with two core guarantees:
  • 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: Select strict or loose JSON mode, or apply regex constraints as needed.
  • OpenAI compatible: Use standard response_format options with OpenAI SDKs.

Structured Outputs Parameters

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, uri
  • object
    • properties
    • additionalProperties is 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 position.
  • array
    • items
    • minItems: We support only 0 or 1 for minItems.

Constant Values and Enumerated Values

const and enum only support constant values of null, boolean, number, and string.

Schema Composition

We support only anyOf 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 as title or description are accepted but ignored.

Simple Example

This example provides a step-by-step guide on 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:

Advanced Examples

For more advanced use cases, see our blog: Structured Output for LLM Agents.
Last modified on July 9, 2026