The toolConfig field must be defined when using toolUse and toolResult content blocks #5062

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

Originally created by @fsatsuki on GitHub (Aug 15, 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.7.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I Use Amazon Bedrock and Claude3.5 Sonnet in the Agent.

Agent uses 5 tools

  • webscraperwebscraper
  • codesimple_code
  • timecurrent_time
  • githubgithub_repositories
  • firecrawlscrape
  • googlegoogle_search

Some time Agent was failed because the above error will occur when switching from having a tool to without a tool after using the tool.

[bedrock] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks.

This is log stream of Bedrock API on the Cloudwatch logs.

{
    "schemaType": "ModelInvocationLog",
    "schemaVersion": "1.0",
    "timestamp": "2024-08-16T00:10:39Z",
    "accountId": "account_id",
    "identity": {
        "arn": "arn:aws:sts::account_id:assumed-role/DifyOnAwsStack-ApiServiceTaskTaskRole06F87EBE-aaRvf0jNQata/34b83c25d18a449a88a67efd56d05b73"
    },
    "region": "us-west-2",
    "requestId": "50f42cca-5c85-499c-8957-d11761ed95cd",
    "operation": "ConverseStream",
    "modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
    "errorCode": "ValidationException"
}

✔️ Expected Behavior

Amazon Bedrock Converse API was succeeded

Actual Behavior

I got this error on the browser.

data: {"event": "error", "conversation_id": "a33d622c-9789-4549-8624-f1a0b55b05a2", "message_id": "e8c15ca2-2d84-49fd-844d-b3a2659a42ac", "created_at": 1723768034, "code": "completion_request_error", "status": 400, "message": "[bedrock] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks."}
Originally created by @fsatsuki on GitHub (Aug 15, 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.7.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I Use Amazon Bedrock and Claude3.5 Sonnet in the Agent. Agent uses 5 tools - webscraperwebscraper - codesimple_code - timecurrent_time - githubgithub_repositories - firecrawlscrape - googlegoogle_search Some time Agent was failed because the above error will occur when switching from having a tool to without a tool after using the tool. ``` [bedrock] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks. ``` This is log stream of Bedrock API on the Cloudwatch logs. ``` { "schemaType": "ModelInvocationLog", "schemaVersion": "1.0", "timestamp": "2024-08-16T00:10:39Z", "accountId": "account_id", "identity": { "arn": "arn:aws:sts::account_id:assumed-role/DifyOnAwsStack-ApiServiceTaskTaskRole06F87EBE-aaRvf0jNQata/34b83c25d18a449a88a67efd56d05b73" }, "region": "us-west-2", "requestId": "50f42cca-5c85-499c-8957-d11761ed95cd", "operation": "ConverseStream", "modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0", "errorCode": "ValidationException" } ``` ### ✔️ Expected Behavior Amazon Bedrock Converse API was succeeded ### ❌ Actual Behavior I got this error on the browser. ``` data: {"event": "error", "conversation_id": "a33d622c-9789-4549-8624-f1a0b55b05a2", "message_id": "e8c15ca2-2d84-49fd-844d-b3a2659a42ac", "created_at": 1723768034, "code": "completion_request_error", "status": 400, "message": "[bedrock] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks."} ```
yindo added the 🙏 help wanted🔨 feat:tools labels 2026-02-21 18:09:12 -05:00
yindo closed this issue 2026-02-21 18:09:13 -05:00
Author
Owner

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

Hey there, @fsatsuki! I'm a bot designed to help you with bug reports, questions, and becoming a contributor. I'm here to assist you while you wait for a human maintainer.

To resolve the ValidationException error in Dify version 0.7.0 when using Amazon Bedrock and Claude3.5 Sonnet in the Agent, you need to ensure that the toolConfig field is defined when using toolUse and toolResult content blocks. This can be done by adding the toolConfig to the parameters if the model supports tool use.

Here is the relevant code snippet that shows how to define the toolConfig:

if model_info['support_tool_use'] and tools:
    parameters['toolConfig'] = self._convert_converse_tool_config(tools=tools)

Make sure that the tools parameter is passed correctly and that the toolConfig is set up properly using the _convert_converse_tool_config method.

Here is the method to convert the tool configuration:

def _convert_converse_tool_config(self, tools: Optional[list[PromptMessageTool]] = None) -> dict:
    tool_config = {}
    configs = []
    if tools:
        for tool in tools:
            configs.append(
                {
                    "toolSpec": {
                        "name": tool.name,
                        "description": tool.description,
                        "inputSchema": {
                            "json": tool.parameters
                        }
                    }
                }
            )
        tool_config["tools"] = configs
    return tool_config

Ensure that the tools parameter is correctly populated and passed to the _invoke method. This will help in defining the toolConfig field and resolving the ValidationException error [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 15, 2024): <!-- Greeting --> Hey there, @fsatsuki! I'm a bot designed to help you with bug reports, questions, and becoming a contributor. I'm here to assist you while you wait for a human maintainer. <!-- Answer --> To resolve the `ValidationException` error in Dify version 0.7.0 when using Amazon Bedrock and Claude3.5 Sonnet in the Agent, you need to ensure that the `toolConfig` field is defined when using `toolUse` and `toolResult` content blocks. This can be done by adding the `toolConfig` to the parameters if the model supports tool use. Here is the relevant code snippet that shows how to define the `toolConfig`: ```python if model_info['support_tool_use'] and tools: parameters['toolConfig'] = self._convert_converse_tool_config(tools=tools) ``` Make sure that the `tools` parameter is passed correctly and that the `toolConfig` is set up properly using the `_convert_converse_tool_config` method. Here is the method to convert the tool configuration: ```python def _convert_converse_tool_config(self, tools: Optional[list[PromptMessageTool]] = None) -> dict: tool_config = {} configs = [] if tools: for tool in tools: configs.append( { "toolSpec": { "name": tool.name, "description": tool.description, "inputSchema": { "json": tool.parameters } } } ) tool_config["tools"] = configs return tool_config ``` Ensure that the `tools` parameter is correctly populated and passed to the `_invoke` method. This will help in defining the `toolConfig` field and resolving the `ValidationException` error <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/bedrock/llm/llm.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@JerrZhang commented on GitHub (Sep 6, 2024):

Is this issue resolved?

@JerrZhang commented on GitHub (Sep 6, 2024): Is this issue resolved?
Author
Owner

@KevinKangnb commented on GitHub (Sep 9, 2024):

image
I have encountered the same problem, please fix it as soon as possible, thank you!!!!

@KevinKangnb commented on GitHub (Sep 9, 2024): ![image](https://github.com/user-attachments/assets/5b024a67-f2fc-432b-ad2b-b848e97e132b) I have encountered the same problem, please fix it as soon as possible, thank you!!!!
Author
Owner

@lalalarabbit commented on GitHub (Sep 9, 2024):

same problem and happens a lot especially when the agent tries to use tools for complex questions.

@lalalarabbit commented on GitHub (Sep 9, 2024): same problem and happens a lot especially when the agent tries to use tools for complex questions.
Author
Owner

@laipz8200 commented on GitHub (Sep 9, 2024):

This issue is caused by the Agent exceeding the maximum limit of 5 tool calls. The same problem occurs with Anthropic's model. We're currently looking into how we can make adjustments.

@laipz8200 commented on GitHub (Sep 9, 2024): This issue is caused by the Agent exceeding the maximum limit of 5 tool calls. The same problem occurs with Anthropic's model. We're currently looking into how we can make adjustments.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5062