Open Router structured output #317

Closed
opened 2026-02-16 10:18:59 -05:00 by yindo · 5 comments
Owner

Originally created by @Rumdaz on GitHub (May 27, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.4.0

Cloud or Self Hosted

Cloud

Steps to reproduce

When using OpenRouter as the provider, some models that originally support structured_output are unable to correctly select the structured_output feature.

✔️ Expected Behavior

OpenRouter's model can also support structured_output automatically or through manual configuration.

Actual Behavior

No response

Originally created by @Rumdaz on GitHub (May 27, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.4.0 ### Cloud or Self Hosted Cloud ### Steps to reproduce When using OpenRouter as the provider, some models that originally support structured_output are unable to correctly select the structured_output feature. ### ✔️ Expected Behavior OpenRouter's model can also support structured_output automatically or through manual configuration. ### ❌ Actual Behavior _No response_
yindo closed this issue 2026-02-16 10:18:59 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (May 27, 2025):

There is a known issue where some models accessed via OpenRouter in Dify do not correctly enable the structured_output feature, even if the underlying model supports it. A similar problem was previously reported for the 4o-mini model and was resolved by introducing a workaround for the json_schema mode, which is one of the structured output formats supported by Dify models. This suggests that structured_output support may depend on both the provider integration and the specific model configuration in Dify, and workarounds or updates may be required for certain models to enable this feature automatically (reference).

Dify provides a UI component for configuring structured output, allowing you to manually define a JSON schema for the model's output. If a model does not support structured output natively, Dify will fall back to prompt injection to approximate the desired structure. You can access this configuration in the workflow node settings, where a modal allows you to define or edit the output schema (reference).

If you encounter a model that does not automatically enable structured_output, you can try manually configuring the schema through the UI. However, if the model or provider integration does not support the required response format (such as json_schema, JSON, or json_object), structured output may not function as expected, and Dify will downgrade to prompt-based formatting (reference).

In summary:

  • Some OpenRouter models may require manual configuration of structured_output in Dify.
  • If the model/provider does not support structured output natively, Dify will use prompt injection as a fallback.
  • A recent workaround for similar issues involved updating how the json_schema mode is handled, so future updates to Dify may improve compatibility for more OpenRouter models.

If you continue to experience issues, it may be related to the current limitations of the provider integration or the specific model's support for structured output formats.

To reply, just mention my name @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (May 27, 2025): <!-- Answer --> There is a known issue where some models accessed via OpenRouter in Dify do not correctly enable the structured_output feature, even if the underlying model supports it. A similar problem was previously reported for the `4o-mini` model and was resolved by introducing a workaround for the `json_schema` mode, which is one of the structured output formats supported by Dify models. This suggests that structured_output support may depend on both the provider integration and the specific model configuration in Dify, and workarounds or updates may be required for certain models to enable this feature automatically [(reference)](https://github.com/langgenius/dify/issues/14475). Dify provides a UI component for configuring structured output, allowing you to manually define a JSON schema for the model's output. If a model does not support structured output natively, Dify will fall back to prompt injection to approximate the desired structure. You can access this configuration in the workflow node settings, where a modal allows you to define or edit the output schema [(reference)](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/llm/components/structure-output.tsx). If you encounter a model that does not automatically enable structured_output, you can try manually configuring the schema through the UI. However, if the model or provider integration does not support the required response format (such as `json_schema`, `JSON`, or `json_object`), structured output may not function as expected, and Dify will downgrade to prompt-based formatting [(reference)](https://github.com/langgenius/dify/blob/main/web/i18n/hi-IN/app.ts). In summary: - Some OpenRouter models may require manual configuration of structured_output in Dify. - If the model/provider does not support structured output natively, Dify will use prompt injection as a fallback. - A recent workaround for similar issues involved updating how the `json_schema` mode is handled, so future updates to Dify may improve compatibility for more OpenRouter models. If you continue to experience issues, it may be related to the current limitations of the provider integration or the specific model's support for structured output formats. <!-- Dosu Comment Footer --> *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/29286e8a-d17c-4753-9408-efcb22046f17?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/29286e8a-d17c-4753-9408-efcb22046f17?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/29286e8a-d17c-4753-9408-efcb22046f17?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/29286e8a-d17c-4753-9408-efcb22046f17?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/29286e8a-d17c-4753-9408-efcb22046f17?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/29286e8a-d17c-4753-9408-efcb22046f17?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/29286e8a-d17c-4753-9408-efcb22046f17?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/20284)
Author
Owner

@davyzhang commented on GitHub (Jun 3, 2025):

For open router there's an unified way to specify json_schema
https://openrouter.ai/docs/features/structured-outputs

The problem is that open router is a growing platform, many models will be added over time.
In my case, I manually added gemini flash 2.0 to model list, and there's no json schema format ui, but it absolutely supports structural output.

I think it's better to let the json schema input ui show with a toggle for open router models.
User will have to decide whether enable it or not

@davyzhang commented on GitHub (Jun 3, 2025): For open router there's an unified way to specify json_schema https://openrouter.ai/docs/features/structured-outputs The problem is that open router is a growing platform, many models will be added over time. In my case, I manually added gemini flash 2.0 to model list, and there's no json schema format ui, but it absolutely supports structural output. I think it's better to let the json schema input ui show with a toggle for open router models. User will have to decide whether enable it or not
Author
Owner

@orangeclk commented on GitHub (Jul 2, 2025):

I will follow up on this issue.

@orangeclk commented on GitHub (Jul 2, 2025): I will follow up on this issue.
Author
Owner

@orangeclk commented on GitHub (Jul 4, 2025):

Following up on my PR #1177, which introduced the structured outputs feature.

The implementation is confirmed to work correctly with OpenAI models, but my tests with the Gemini series were unsuccessful.

There appears to be conflicting information from OpenRouter on this:

  • Their documentation only mentions support for OpenAI and Fireworks models.
  • However, their model list indicates that the Gemini series is compatible with the structured_outputs parameter.

This discrepancy suggests the intended behavior for Gemini's structured outputs via OpenRouter is currently undefined or inconsistent. Clarification on this would be helpful.

@orangeclk commented on GitHub (Jul 4, 2025): Following up on my PR #1177, which introduced the structured outputs feature. The implementation is confirmed to work correctly with OpenAI models, but my tests with the Gemini series were unsuccessful. There appears to be conflicting information from OpenRouter on this: - Their [documentation](https://openrouter.ai/docs/features/structured-outputs) only mentions support for OpenAI and Fireworks models. - However, their [model list](https://openrouter.ai/models?fmt=cards&order=top-weekly&supported_parameters=structured_outputs) indicates that the Gemini series is compatible with the `structured_outputs` parameter. This discrepancy suggests the intended behavior for Gemini's structured outputs via OpenRouter is currently undefined or inconsistent. Clarification on this would be helpful.
Author
Owner

@dosubot[bot] commented on GitHub (Aug 20, 2025):

Hi, @Rumdaz. I'm Dosu, and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that some OpenRouter models in Dify v1.4.0 (Cloud) do not properly enable structured_output despite supporting it.
  • It was explained that structured_output may require manual JSON schema configuration in the UI, with fallback to prompt injection if unsupported.
  • OpenRouter has a unified json_schema spec, but many models like Gemini Flash 2.0 lack UI support for structured output.
  • A toggle for users to enable structured output was suggested to address this gap.
  • There is some confusion about Gemini series support due to conflicting OpenRouter documentation and model listings.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of dify-official-plugins, and if so, you can keep the discussion open by commenting here.
  • Otherwise, I will automatically close this issue in 5 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 20, 2025): Hi, @Rumdaz. I'm [Dosu](https://dosu.dev), and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that some OpenRouter models in Dify v1.4.0 (Cloud) do not properly enable structured_output despite supporting it. - It was explained that structured_output may require manual JSON schema configuration in the UI, with fallback to prompt injection if unsupported. - OpenRouter has a unified json_schema spec, but many models like Gemini Flash 2.0 lack UI support for structured output. - A toggle for users to enable structured output was suggested to address this gap. - There is some confusion about Gemini series support due to conflicting OpenRouter documentation and model listings. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of dify-official-plugins, and if so, you can keep the discussion open by commenting here. - Otherwise, I will automatically close this issue in 5 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#317