---
title: Structured Outputs
---

## Overview

Dify’s structured outputs ensures LLMs return data in predictable JSON formats, making the output easier to process and integrate into applications.

## Benefits

- **Consistent Data Formatting**: All LLM-generated content follows predefined formats, eliminating data inconsistencies.

- **Seamless Integration**: : Databases, APIs, or frontend applications can directly parse JSON Schema without additional data cleaning.

- **Simplified Development**: Developers can skip writing complex validation code by letting JSON Schema handle output constraints.

## Implementation Methods

Dify offers two ways to create structured outputs:

### Method 1: Tool Parameters

Define your output structure directly in tool parameters. See **[Tool](https://docs.dify.ai/plugins/schema-definition/tool) > Data Structures > Return Variable Definitions**.

### Method 2: JSON Schema Editor

Use the built-in editor in LLM nodes. See **[LLM](https://docs.dify.ai/guides/workflow/node/llm) > Advanced Features > Structured Outputs** and **[LLM](https://docs.dify.ai/guides/workflow/node/llm) > Use Cases > Structured Outputs**.

## Error Handling

**What Can Go Wrong**

When you are working with the JSON Schema Editor, you might run into a few common challenges:

- **Limited Model Performance**: Smaller LLMs (like GPT-3.5 Turbo) sometimes have trouble following JSON Schema instructions correctly.

- **Format Issues**: Some LLMs only understand basic JSON, not full JSON Schema.

- **Error Messages**: You might see `Failed to parse structured output: output is not a valid json str` when the model fails to generate proper JSON.

**How to Fix These Issues**

1.  **Choose the Right Model**. These models work best with JSON Schema:
    - Gemini 2.0 Flash/Flash-Lite
    - Gemini 1.5 Flash 8B (versions 0827/0924)
    - Gemini-1.5 pro
    - GPT-4o and GPT-4o-mini
    - o1-mini/o3-mini series

2.  **Write Clear Instructions**. Make sure your prompts match what you are trying to do. For example, if you need mathematical formulas, don’t ask for legal analysis—this helps the AI understand exactly what you need.

3.  **Have a Backup Plan**.

    1. Enable **Retry on Failure** with custom retry attempts and intervals.

    2. Set up **Failure Branch** to handle any errors.

See [Error Handling](https://docs.dify.ai/guides/workflow/error-handling) for more details.

{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}

---

[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/guides/workflow/structured-outputs.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?title=Documentation%20Issue%3A%20tured-outp&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fen/guides/workflow%2Fstructured-outputs.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E)

