langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
49.45k stars 7.07k forks source link

Can't pass number to workflow tool #9861

Open JokerQyou opened 3 hours ago

JokerQyou commented 3 hours ago

Self Checks

Dify version

0.10.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create a workflow, add an input variable of number type, the publish this workflow as a tool.
  2. Create another workflow, also add an input variable of number type, then add a tool node, select previous workflow as tool, in tool input variable section, pass the input number to this tool.
  3. Run the second workflow with a random number.

Here is these two workflows (file extension changed to .txt due to GitHub issue restriction): test-tool is the tool workflow, test is the workflow to reproduce this bug.

test.yml.txt test-tool.yml.txt

Screenshot of variable passing to tool workflow: image

Screenshot of type error during workflow execution: image

The error text is:

1 validation error for ToolNodeData tool_parameters.i.type Value error, value must be a string, int, float, or bool [type=value_error, input_value='constant', input_type=str] For further information visit https://errors.pydantic.dev/2.9/v/value_error

I checked multiple times that this is not due to my app code bug like mismatched variable type configured on the UI or something like that. This seems to be a dify bug.

test.yml.txt test-tool.yml.txt

✔️ Expected Behavior

The test workflow runs fine.

❌ Actual Behavior

Errors out with 1 validation error for ToolNodeData tool_parameters.i.type Value error, value must be a string, int, float, or bool [type=value_error, input_value='constant', input_type=str].

dosubot[bot] commented 3 hours ago

To resolve the validation error you're encountering in the Dify workflow tool, ensure that the number is passed as a type that the tool node expects. According to the Dify code, the ToolInput class expects the value to be of type str, int, float, or bool when the type is "constant".

Here's how you can ensure the correct type is passed:

  1. If the type is "constant", make sure the value is explicitly cast to one of the accepted types (str, int, float, or bool). For example, if you are passing a number, ensure it is not wrapped in a list or any other structure.

Example:

tool_input = ToolNodeData.ToolInput(value=42, type="constant")
  1. If the type is "mixed", ensure the value is a string.

Example:

tool_input = ToolNodeData.ToolInput(value="42", type="mixed")
  1. If the type is "variable", ensure the value is a list of strings.

Example:

tool_input = ToolNodeData.ToolInput(value=["42"], type="variable")

By ensuring the value matches the expected type for the specified type, you should be able to resolve the validation error [1].

To continue talking to Dosu, mention @dosu.

JokerQyou commented 3 hours ago

Of course I passed it as number. You can import the workflows I uploaded (in the first comment) to check it yourself. Also I'm on a docker installation so there is no easy way to tweak dify source code, so can't verify what you suggested.