Overview
Configure structured output for LLM nodes in Dify workflows to enforce JSON schema on model responses.
Prerequisites
- Dify workflow with at least one LLM node
- LLM node selected in the editor
Access Structured Output Settings
- Click on an LLM node in the workflow canvas
- In the right panel, scroll to "Output Variables" section
- Find "Structured" label with a toggle switch next to it
Enable Structured Output
- Click the toggle switch next to "Structured" to enable
- Message appears: "Structured output has not been configured yet"
- Click button "Configure" to open schema editor
Schema Editor Dialog
Dialog title: "Structured Output Schema"
Editor Tabs
| Tab | Purpose |
|---|---|
| Visual Editor | User-friendly field builder |
| JSON Schema | Direct JSON schema input |
Visual Editor Features
- Shows field hierarchy (structured_output > fields)
- Each field displays: name, type, required status
- button "Add Field" - Add new field to schema
JSON Schema Features
- Direct JSON Schema editing
- Line numbers displayed
- Syntax error messages shown below editor
Import Schema from Sample JSON
Fastest method to create schema:
- Click button "Import from JSON"
- Tooltip dialog opens with:
- input "Editor content" - Paste sample JSON here
- button "Cancel"
- button "Submit"
- Paste a sample JSON object representing desired output structure
- Click "Submit" to auto-generate schema from sample
Example Sample JSON
\{"records":[\{"date":"2020-08-01","value":"100","category":"A"\}]\}
This generates schema with:
- records (array[object]) - required
- date (string) - required
- value (string) - required
- category (string) - required
Save Schema
- Review schema in Visual Editor tab
- Click button "Save" to apply
- Dialog closes
- "Configure" button appears next to Structured toggle
- Output Variables section shows new structured_output field
Dialog Buttons
| Button | Action |
|---|---|
| Reset | Clear schema to default empty object |
| Cancel | Close without saving |
| Save | Apply schema configuration |
Tips
- Use "Import from JSON" for quick schema creation
- Visual Editor is easier for reviewing/editing existing schema
- JSON Schema tab may show validation errors - switch to Visual Editor to verify
- Models with native JSON support (GPT-4, Claude) provide more reliable structured output
- After configuring, update system prompt to request JSON format instead of plain text
Output Variables After Configuration
Once configured, Output Variables section shows:
- text (string) - Generate content
- reasoning_content (string) - Reasoning Content
- usage (object) - Model Usage Information
- structured_output (object) - Your configured schema