Structured Outputs
Structured outputs ensure LLM responses follow specific formats, making them easier to use in your applications. For more advanced structured data requirements, you may also want to check out our Tool Calling documentation.
What are Structured Outputs?
Structured outputs define formats LLMs must follow when generating responses:
- Consistent response formats
- Easier parsing and validation
- More reliable integration with your applications
- Less error handling
Examples include customer records, product information, and analytical results.
Creating Structured Outputs with JSON Schema
To add a JSON schema to your prompt template:
- Edit your prompt template
- Click “Add Response Format”
- Select “JSON Schema”
- Define your schema structure
Example: Customer Review Analysis Schema
Using Variables in Structured Outputs
You can make your schemas dynamic by using template variables:
Variables in structured outputs only work with Jinja2 format with the Jinja2 option enabled. F-string format isn’t supported.
Interactive Mode
When using the interactive schema editor, you can add variables in two ways:
- For enum values: Click the enum field and toggle the switch to “Use Variable”
- For text/string values: Type
{{ variable_name }}
directly in any text field
JSON Mode
Variables must be in quotes, except for enum variables:
When running the prompt, provide your variables:
For more information on template variables, see our Template Variables documentation.
Best Practices
- For enum values: Use
{name: "variable_name", type: "enum_variable"}
in JSON mode or the variable selector in interactive mode - For text variables: Include them within quotes as
{{ variable_name }}
in both modes - Only Jinja2 format works for variables in structured outputs
- Ensure all variables used in the schema are provided
- Use proper JSON formatting with variables
Was this page helpful?