dify icon indicating copy to clipboard operation
dify copied to clipboard

The Numeric Type in Structured Output Cannot Be Recognized by Downstream Components

Open pandy1715 opened this issue 8 months ago • 2 comments

Self Checks

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

Dify version

1.3.0

Cloud or Self Hosted

Cloud

Steps to reproduce

When using the system, the upstream model defines a structured output of type number. However, the downstream branch node fails to recognize it, resulting in an error during execution: Invalid actual value type: string.

Image

✔️ Expected Behavior

Expectation: The system should recognize the value as a Number and execute the branch logic based on numeric type. Image

❌ Actual Behavior

Invalid actual value type: string

Image

pandy1715 avatar Apr 25 '25 07:04 pandy1715

Hello @pandy1715! I'm Dosu, your friendly bot here to help you tackle bugs, answer questions, and guide you on your journey to becoming a contributor. I'm here while you wait for a human maintainer. Let's get started!

To resolve the issue where the downstream components fail to recognize a numeric type in the structured output, resulting in an "Invalid actual value type: string" error, ensure that the output adheres to the JSON schema specified in the STRUCTURED_OUTPUT_PROMPT. Specifically, make sure that numeric values are output as numbers, not strings.

For example, if the JSON schema specifies a property with "type": "number", the output should be:

{"name": "John Doe", "age": 30}

Ensure that the numeric values are not enclosed in quotes, as this would make them strings [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 25 '25 07:04 dosubot[bot]

Image @dosu

pandy1715 avatar Apr 25 '25 07:04 pandy1715

I ran into a similar issue. One workaround is to use "string" as the structured output type instead of "Number". It is annoying, though.

Lw-Cui avatar Jul 16 '25 13:07 Lw-Cui

I have a same issue with this on Dify 1.6.0. I create structured output as numeric, but next if-statement deal it as string.

Image

t-ikeda-mm avatar Aug 01 '25 11:08 t-ikeda-mm

https://cloud.dify.ai/ 1.7.2 I defined the variable as ​number​ in Structured Outputs, but it ​outputs as string.

"model_provider": "langgenius/siliconflow/siliconflow", "model_name": "deepseek-ai/DeepSeek-V3"

Image Image

dq7532183 avatar Aug 16 '25 13:08 dq7532183

Hi, @pandy1715. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that numeric structured outputs in Dify 1.3.0 Cloud are incorrectly treated as strings by downstream branch nodes, causing execution errors.
  • The suggested fix was to ensure numeric values are output as JSON numbers per the structured output schema.
  • Other users confirmed the issue persists in versions 1.6.0 and 1.7.2.
  • A common workaround has been to define the output type as string, which is inconvenient.
  • The issue remains unresolved with no official fix implemented yet.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of Dify by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Sep 16 '25 16:09 dosubot[bot]