The tool parameter of number type not support float value #5212

Closed
opened 2026-02-21 18:09:54 -05:00 by yindo · 1 comment
Owner

Originally created by @hjlarry on GitHub (Aug 26, 2024).

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

0.7.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

In a tool's config file, set the params like this:

  - name: guidance_scale
    type: number
    required: true
    default: 7.5
    min: 0
    max: 100
    label:
      en_US: Guidance Scale
      zh_Hans: 与提示词紧密性
    form: form

✔️ Expected Behavior

No response

Actual Behavior

raise Exception:

{
    "code": "invalid_param",
    "message": "2 validation errors for StableDiffusionTool\nparameters.5.default.int\n  Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=7.5, input_type=float]\n    For further information visit https://errors.pydantic.dev/2.8/v/int_from_float\nparameters.5.default.str\n  Input should be a valid string [type=string_type, input_value=7.5, input_type=float]\n    For further information visit https://errors.pydantic.dev/2.8/v/string_type",
    "status": 400
}
Originally created by @hjlarry on GitHub (Aug 26, 2024). ### 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 0.7.1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce In a tool's config file, set the params like this: ``` - name: guidance_scale type: number required: true default: 7.5 min: 0 max: 100 label: en_US: Guidance Scale zh_Hans: 与提示词紧密性 form: form ``` ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior raise Exception: ``` { "code": "invalid_param", "message": "2 validation errors for StableDiffusionTool\nparameters.5.default.int\n Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=7.5, input_type=float]\n For further information visit https://errors.pydantic.dev/2.8/v/int_from_float\nparameters.5.default.str\n Input should be a valid string [type=string_type, input_value=7.5, input_type=float]\n For further information visit https://errors.pydantic.dev/2.8/v/string_type", "status": 400 } ```
yindo added the 🐞 bug label 2026-02-21 18:09:54 -05:00
yindo closed this issue 2026-02-21 18:09:54 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 26, 2024):

The tool parameter of type number does support float values in Dify version 0.7.1. The cast_parameter_by_type method in the ToolParameterConverter class handles both integer and float values for the ToolParameter.ToolParameterType.NUMBER type. Here is the relevant code snippet:

case ToolParameter.ToolParameterType.NUMBER:
    if isinstance(value, int) | isinstance(value, float):
        return value
    elif isinstance(value, str) and value != '':
        if '.' in value:
            return float(value)
        else:
            return int(value)

This code shows that if the value is a float or can be converted to a float (i.e., it contains a '.'), it will be correctly handled as a float [1].

The error you are encountering seems to be related to the validation rules defined in the configuration schema. Specifically, the default value of 7.5 is being interpreted as a float, but the validation expects an integer. Ensure that the default value is correctly specified as a float and that the validation rules allow for float values.

If the issue persists, you might want to check the specific validation rules or constraints defined for the number type parameters in the configuration schema. These include min, max, and precision constraints, which ensure that numeric parameters adhere to specified ranges and precision levels [2][3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 26, 2024): <!-- Answer --> The tool parameter of type `number` does support float values in Dify version 0.7.1. The `cast_parameter_by_type` method in the `ToolParameterConverter` class handles both integer and float values for the `ToolParameter.ToolParameterType.NUMBER` type. Here is the relevant code snippet: ```python case ToolParameter.ToolParameterType.NUMBER: if isinstance(value, int) | isinstance(value, float): return value elif isinstance(value, str) and value != '': if '.' in value: return float(value) else: return int(value) ``` This code shows that if the value is a float or can be converted to a float (i.e., it contains a '.'), it will be correctly handled as a float <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/utils/tool_parameter_converter.py)</sup>. The error you are encountering seems to be related to the validation rules defined in the configuration schema. Specifically, the `default` value of `7.5` is being interpreted as a float, but the validation expects an integer. Ensure that the `default` value is correctly specified as a float and that the validation rules allow for float values. If the issue persists, you might want to check the specific validation rules or constraints defined for the `number` type parameters in the configuration schema. These include `min`, `max`, and `precision` constraints, which ensure that numeric parameters adhere to specified ranges and precision levels <sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/model-configuration/schema.md)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/__base/large_language_model.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5212