dify and VANNA.AI #5012

Closed
opened 2026-02-21 18:09:00 -05:00 by yindo · 7 comments
Owner

Originally created by @renjiarui021020 on GitHub (Aug 13, 2024).

Originally assigned to: @laipz8200 on GitHub.

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.6.16

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Node Vanna.AI run failed: Failed to invoke tool: 3 validation errors for ToolInvokeMessage message.str Input should be a valid string [type=string_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/string_type message.bytes Input should be a valid bytes [type=bytes_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/bytes_type message.dict[any,any] Input should be a valid dictionary [type=dict_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/dict_type
4015f96d3c0eafe36661d07db905c3a
新建 Text Document.txt

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @renjiarui021020 on GitHub (Aug 13, 2024). Originally assigned to: @laipz8200 on GitHub. ### 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.6.16 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Node Vanna.AI run failed: Failed to invoke tool: 3 validation errors for ToolInvokeMessage message.str Input should be a valid string [type=string_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/string_type message.bytes Input should be a valid bytes [type=bytes_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/bytes_type message.dict[any,any] Input should be a valid dictionary [type=dict_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.8/v/dict_type ![4015f96d3c0eafe36661d07db905c3a](https://github.com/user-attachments/assets/021c3ff9-ca35-4537-8a5a-6980c96b52f1) [新建 Text Document.txt](https://github.com/user-attachments/files/16595131/Text.Document.txt) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug🙏 help wanted labels 2026-02-21 18:09:00 -05:00
yindo closed this issue 2026-02-21 18:09:00 -05:00
Author
Owner

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

To resolve the pydantic validation errors for string, bytes, and dictionary types when running the Node Vanna.AI in Dify version 0.6.16, you need to ensure that the tool_configurations and ToolInput fields are validated correctly according to their expected types.

Here is the relevant code with the necessary validation logic:

from typing import Any, Literal, Union

from pydantic import BaseModel, field_validator
from pydantic_core.core_schema import ValidationInfo

from core.workflow.entities.base_node_data_entities import BaseNodeData


class ToolEntity(BaseModel):
    provider_id: str
    provider_type: Literal['builtin', 'api', 'workflow']
    provider_name: str # redundancy
    tool_name: str
    tool_label: str # redundancy
    tool_configurations: dict[str, Any]

    @field_validator('tool_configurations', mode='before')
    @classmethod
    def validate_tool_configurations(cls, value, values: ValidationInfo):
        if not isinstance(value, dict):
            raise ValueError('tool_configurations must be a dictionary')
        
        for key in value.keys():
            val = value[key]
            if not isinstance(val, (str, int, float, bool)):
                raise ValueError(f'{key} must be a string, int, float, or bool')
            
        return value

class ToolNodeData(BaseNodeData, ToolEntity):
    class ToolInput(BaseModel):
        value: Union[Any, list[str]]
        type: Literal['mixed', 'variable', 'constant']

        @field_validator('type', mode='before')
        @classmethod
        def check_type(cls, value, validation_info: ValidationInfo):
            typ = value
            val = validation_info.data.get('value')
            if typ == 'mixed' and not isinstance(val, str):
                raise ValueError('value must be a string')
            elif typ == 'variable':
                if not isinstance(val, list):
                    raise ValueError('value must be a list')
                for item in val:
                    if not isinstance(item, str):
                        raise ValueError('value must be a list of strings')
            elif typ == 'constant' and not isinstance(val, (str, int, float, bool)):
                raise ValueError('value must be a string, int, float, or bool')
            return typ

    """
    Tool Node Schema
    """
    tool_parameters: dict[str, ToolInput]

This code ensures that:

  1. tool_configurations must be a dictionary where each value is a string, int, float, or bool.
  2. ToolInput's value field is validated based on the type field:
    • If type is 'mixed', value must be a string.
    • If type is 'variable', value must be a list of strings.
    • If type is 'constant', value must be a string, int, float, or bool [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 13, 2024): <!-- Answer --> To resolve the pydantic validation errors for string, bytes, and dictionary types when running the Node Vanna.AI in Dify version 0.6.16, you need to ensure that the `tool_configurations` and `ToolInput` fields are validated correctly according to their expected types. Here is the relevant code with the necessary validation logic: ```python from typing import Any, Literal, Union from pydantic import BaseModel, field_validator from pydantic_core.core_schema import ValidationInfo from core.workflow.entities.base_node_data_entities import BaseNodeData class ToolEntity(BaseModel): provider_id: str provider_type: Literal['builtin', 'api', 'workflow'] provider_name: str # redundancy tool_name: str tool_label: str # redundancy tool_configurations: dict[str, Any] @field_validator('tool_configurations', mode='before') @classmethod def validate_tool_configurations(cls, value, values: ValidationInfo): if not isinstance(value, dict): raise ValueError('tool_configurations must be a dictionary') for key in value.keys(): val = value[key] if not isinstance(val, (str, int, float, bool)): raise ValueError(f'{key} must be a string, int, float, or bool') return value class ToolNodeData(BaseNodeData, ToolEntity): class ToolInput(BaseModel): value: Union[Any, list[str]] type: Literal['mixed', 'variable', 'constant'] @field_validator('type', mode='before') @classmethod def check_type(cls, value, validation_info: ValidationInfo): typ = value val = validation_info.data.get('value') if typ == 'mixed' and not isinstance(val, str): raise ValueError('value must be a string') elif typ == 'variable': if not isinstance(val, list): raise ValueError('value must be a list') for item in val: if not isinstance(item, str): raise ValueError('value must be a list of strings') elif typ == 'constant' and not isinstance(val, (str, int, float, bool)): raise ValueError('value must be a string, int, float, or bool') return typ """ Tool Node Schema """ tool_parameters: dict[str, ToolInput] ``` This code ensures that: 1. `tool_configurations` must be a dictionary where each value is a string, int, float, or bool. 2. `ToolInput`'s `value` field is validated based on the `type` field: - If `type` is 'mixed', `value` must be a string. - If `type` is 'variable', `value` must be a list of strings. - If `type` is 'constant', `value` must be a string, int, float, or bool <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/tool/entities.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@renjiarui021020 commented on GitHub (Aug 13, 2024):

@dosu. I used your code but still got the same error

@renjiarui021020 commented on GitHub (Aug 13, 2024): @dosu. I used your code but still got the same error
Author
Owner

@renjiarui021020 commented on GitHub (Aug 13, 2024):

I am VANNA in the workflow Is there a problem with the configuration filled in by AI

@renjiarui021020 commented on GitHub (Aug 13, 2024): I am VANNA in the workflow Is there a problem with the configuration filled in by AI
Author
Owner

@crazywoola commented on GitHub (Aug 13, 2024):

I left a comment in #4878 , maybe @luxmus could help with this issue.

@crazywoola commented on GitHub (Aug 13, 2024): I left a comment in #4878 , maybe @luxmus could help with this issue.
Author
Owner

@renjiarui021020 commented on GitHub (Aug 13, 2024):

Thank you for your help, but I carefully read the article and did not find any mistakes on my part

@renjiarui021020 commented on GitHub (Aug 13, 2024): Thank you for your help, but I carefully read the article and did not find any mistakes on my part
Author
Owner

@renjiarui021020 commented on GitHub (Aug 14, 2024):

@laipz8200 Thank you for your help. But I made the modifications according to your code, and still got the same error.

@renjiarui021020 commented on GitHub (Aug 14, 2024): @laipz8200 Thank you for your help. But I made the modifications according to your code, and still got the same error.
Author
Owner

@WWei0728 commented on GitHub (Oct 31, 2024):

vanna的API key 填写无效报错,什么原因

@WWei0728 commented on GitHub (Oct 31, 2024): vanna的API key 填写无效报错,什么原因
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5012