Skip to main content
Structured output allows you to define a JSON schema that constrains the LLM’s response format. This ensures consistent, validated outputs that are easier to parse and integrate into your applications.

Overview

With structured output, you can specify the exact structure you want the model to return, including:
  • Required and optional fields
  • Data types for each field
  • Nested objects and arrays
  • Enumerations and constraints

Configuring Structured Output

Structured output is configured using the Text parameter in your request. You provide a JSON schema that defines the expected output structure.

Example: Extracting Structured Data

Here’s a complete example that extracts structured information from unstructured text:

Schema Format

The schema follows the JSON Schema specification. Key components:

Basic Types

Nested Objects

Enumerations


Strict vs Non-Strict Mode

The strict parameter controls how strictly the model adheres to the schema:
  • strict: false (default): The model can be more flexible and may include additional fields or slightly deviate from the schema if it helps generate better responses.
  • strict: true: The model must strictly follow the schema with no deviations.

Streaming with Structured Output

Structured output also works with streaming responses. The model will stream the JSON structure incrementally: