Solutions for AWS Bedrock Claude Tooluse Error: The toolConfig field must be defined when using toolUse and toolResult content blocks #11922

Closed
opened 2026-02-21 19:04:46 -05:00 by yindo · 9 comments
Owner

Originally created by @ghost on GitHub (Mar 20, 2025).

Originally assigned to: @crazywoola 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.15.3

Cloud or Self Hosted

Self-hosted

Steps to reproduce

import boto3
from botocore.config import Config

my_config = Config(
    region_name = 'us-east-1',
    signature_version = 'v4',
    retries = {
        'max_attempts': 10,
        'mode': 'standard'
    }
)

client = boto3.client(service_name='bedrock-runtime', config=my_config)

messages = [
    {
        'role': 'user',
        'content': [
            {
                'text': "What is the weather in Shanghai?"
            }
        ]
    }
]

response = client.converse(
    modelId='anthropic.claude-3-5-sonnet-20240620-v1:0',
    messages=messages,
    inferenceConfig={
        'maxTokens': 2000
    },
    toolConfig={
        'tools': [
            {
                'toolSpec': {
                    'name': 'get_weather',
                    'description': 'Get the current weather in a given location',
                    'inputSchema': {
                        'json': {
                            'type': 'object',
                            'properties': {
                                'location': {
                                    'type': 'string',
                                    'description': 'The city and state, e.g. San Francisco, CA',
                                }
                            },
                            'required': ['location']
                        }
                    }
                }
            }
        ]
    },
)
print(response, "\n\n")
assistant_message = response['output']['message']
messages.append(assistant_message)

if any(content.get('toolUse') for content in assistant_message['content']):
    for content in assistant_message['content']:
        if 'toolUse' in content:
            tool_use = content['toolUse']

            weather_result = "8 degrees Celsius, sunny, good air quality."
            
            tool_response = {
                'role': 'user',
                'content': [
                    {
                        'toolResult': {
                            'toolUseId': tool_use['toolUseId'],
                            'content': [
                                {
                                    'text': weather_result
                                }
                            ],
                            'status': 'success'
                        }
                    }
                ]
            }
            
            messages.append(tool_response)

print("messages: \n", messages, "\n\n")

new_response = client.converse(
    modelId='anthropic.claude-3-5-sonnet-20240620-v1:0',
    messages=messages,
    inferenceConfig={
        'maxTokens': 2000
    }
)

print(new_response)

See the output and error:

{'ResponseMetadata': {'RequestId': '850908b3-b5b2-4e6c-97a9-a747d5acfa49', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 21 Mar 2025 03:47:54 GMT', 'content-type': 'application/json', 'content-length': '417', 'connection': 'keep-alive', 'x-amzn-requestid': '850908b3-b5b2-4e6c-97a9-a747d5acfa49'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': 'To get the current weather in Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_5WhMVIKSRhiB_pKX9DcQIw', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}}, 'stopReason': 'tool_use', 'usage': {'inputTokens': 382, 'outputTokens': 81, 'totalTokens': 463}, 'metrics': {'latencyMs': 2105}} 


messages: 
 [{'role': 'user', 'content': [{'text': 'What is the weather in Shanghai?'}]}, {'role': 'assistant', 'content': [{'text': 'To get the current weather in Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_5WhMVIKSRhiB_pKX9DcQIw', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}, {'role': 'user', 'content': [{'toolResult': {'toolUseId': 'tooluse_5WhMVIKSRhiB_pKX9DcQIw', 'content': [{'text': '8 degrees Celsius, sunny, good air quality.'}], 'status': 'success'}}]}] 

**botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the Converse operation: The toolConfig field must be defined when using toolUse and toolResult content blocks.**

See solution below:

✔️ Expected Behavior

new_response = client.converse(
    modelId='anthropic.claude-3-5-sonnet-20240620-v1:0',
    messages=messages,
    inferenceConfig={
        'maxTokens': 2000
    },
    toolConfig={
        'tools': [
            {
                'toolSpec': {
                    'name': 'get_weather',
                    'description': 'Get the current weather in a given location',
                    'inputSchema': {
                        'json': {
                            'type': 'object',
                            'properties': {
                                'location': {
                                    'type': 'string',
                                    'description': 'The city and state, e.g. San Francisco, CA',
                                }
                            },
                            'required': ['location']
                        }
                    }
                }
            }
        ]
    },
)

print(new_response)

See the right ouput:

{'ResponseMetadata': {'RequestId': '80f66235-8776-4e02-a6be-877b9e88c500', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 21 Mar 2025 03:50:41 GMT', 'content-type': 'application/json', 'content-length': '422', 'connection': 'keep-alive', 'x-amzn-requestid': '80f66235-8776-4e02-a6be-877b9e88c500'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': 'To get the weather information for Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_aWyYTrP_T0el1eqykO_pQQ', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}}, 'stopReason': 'tool_use', 'usage': {'inputTokens': 382, 'outputTokens': 81, 'totalTokens': 463}, 'metrics': {'latencyMs': 2259}} 


messages: 
 [{'role': 'user', 'content': [{'text': 'What is the weather in Shanghai?'}]}, {'role': 'assistant', 'content': [{'text': 'To get the weather information for Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_aWyYTrP_T0el1eqykO_pQQ', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}, {'role': 'user', 'content': [{'toolResult': {'toolUseId': 'tooluse_aWyYTrP_T0el1eqykO_pQQ', 'content': [{'text': '8 degrees Celsius, sunny, good air quality.'}], 'status': 'success'}}]}] 


{'ResponseMetadata': {'RequestId': 'fb2d8ad1-a8b4-4a85-9c1d-71326e62c3d5', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 21 Mar 2025 03:50:47 GMT', 'content-type': 'application/json', 'content-length': '843', 'connection': 'keep-alive', 'x-amzn-requestid': 'fb2d8ad1-a8b4-4a85-9c1d-71326e62c3d5'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': "Based on the information I've received, here's the current weather in Shanghai:\n\nThe temperature is 8 degrees Celsius (which is about 46 degrees Fahrenheit). The sky is sunny, and the air quality is reported as good.\n\nThis weather is typical for Shanghai during certain times of the year, especially in late autumn or early spring. The sunny conditions and good air quality make it a pleasant day in the city. However, it's relatively cool, so if you're in Shanghai or planning to visit, you might want to wear a light jacket or sweater when going outside.\n\nIs there anything else you'd like to know about the weather in Shanghai or any other location?"}]}}, 'stopReason': 'end_turn', 'usage': {'inputTokens': 485, 'outputTokens': 147, 'totalTokens': 632}, 'metrics': {'latencyMs': 5241}}

Actual Behavior

No response

Originally created by @ghost on GitHub (Mar 20, 2025). Originally assigned to: @crazywoola 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.15.3 ### Cloud or Self Hosted Self-hosted ### Steps to reproduce ``` python import boto3 from botocore.config import Config my_config = Config( region_name = 'us-east-1', signature_version = 'v4', retries = { 'max_attempts': 10, 'mode': 'standard' } ) client = boto3.client(service_name='bedrock-runtime', config=my_config) messages = [ { 'role': 'user', 'content': [ { 'text': "What is the weather in Shanghai?" } ] } ] response = client.converse( modelId='anthropic.claude-3-5-sonnet-20240620-v1:0', messages=messages, inferenceConfig={ 'maxTokens': 2000 }, toolConfig={ 'tools': [ { 'toolSpec': { 'name': 'get_weather', 'description': 'Get the current weather in a given location', 'inputSchema': { 'json': { 'type': 'object', 'properties': { 'location': { 'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA', } }, 'required': ['location'] } } } } ] }, ) print(response, "\n\n") assistant_message = response['output']['message'] messages.append(assistant_message) if any(content.get('toolUse') for content in assistant_message['content']): for content in assistant_message['content']: if 'toolUse' in content: tool_use = content['toolUse'] weather_result = "8 degrees Celsius, sunny, good air quality." tool_response = { 'role': 'user', 'content': [ { 'toolResult': { 'toolUseId': tool_use['toolUseId'], 'content': [ { 'text': weather_result } ], 'status': 'success' } } ] } messages.append(tool_response) print("messages: \n", messages, "\n\n") new_response = client.converse( modelId='anthropic.claude-3-5-sonnet-20240620-v1:0', messages=messages, inferenceConfig={ 'maxTokens': 2000 } ) print(new_response) ``` See the output and error: ```ouput {'ResponseMetadata': {'RequestId': '850908b3-b5b2-4e6c-97a9-a747d5acfa49', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 21 Mar 2025 03:47:54 GMT', 'content-type': 'application/json', 'content-length': '417', 'connection': 'keep-alive', 'x-amzn-requestid': '850908b3-b5b2-4e6c-97a9-a747d5acfa49'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': 'To get the current weather in Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_5WhMVIKSRhiB_pKX9DcQIw', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}}, 'stopReason': 'tool_use', 'usage': {'inputTokens': 382, 'outputTokens': 81, 'totalTokens': 463}, 'metrics': {'latencyMs': 2105}} messages: [{'role': 'user', 'content': [{'text': 'What is the weather in Shanghai?'}]}, {'role': 'assistant', 'content': [{'text': 'To get the current weather in Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_5WhMVIKSRhiB_pKX9DcQIw', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}, {'role': 'user', 'content': [{'toolResult': {'toolUseId': 'tooluse_5WhMVIKSRhiB_pKX9DcQIw', 'content': [{'text': '8 degrees Celsius, sunny, good air quality.'}], 'status': 'success'}}]}] **botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the Converse operation: The toolConfig field must be defined when using toolUse and toolResult content blocks.** ``` See solution below: ### ✔️ Expected Behavior ```python new_response = client.converse( modelId='anthropic.claude-3-5-sonnet-20240620-v1:0', messages=messages, inferenceConfig={ 'maxTokens': 2000 }, toolConfig={ 'tools': [ { 'toolSpec': { 'name': 'get_weather', 'description': 'Get the current weather in a given location', 'inputSchema': { 'json': { 'type': 'object', 'properties': { 'location': { 'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA', } }, 'required': ['location'] } } } } ] }, ) print(new_response) ``` See the right ouput: ```output {'ResponseMetadata': {'RequestId': '80f66235-8776-4e02-a6be-877b9e88c500', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 21 Mar 2025 03:50:41 GMT', 'content-type': 'application/json', 'content-length': '422', 'connection': 'keep-alive', 'x-amzn-requestid': '80f66235-8776-4e02-a6be-877b9e88c500'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': 'To get the weather information for Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_aWyYTrP_T0el1eqykO_pQQ', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}}, 'stopReason': 'tool_use', 'usage': {'inputTokens': 382, 'outputTokens': 81, 'totalTokens': 463}, 'metrics': {'latencyMs': 2259}} messages: [{'role': 'user', 'content': [{'text': 'What is the weather in Shanghai?'}]}, {'role': 'assistant', 'content': [{'text': 'To get the weather information for Shanghai, I can use the get_weather function. Let me fetch that information for you.'}, {'toolUse': {'toolUseId': 'tooluse_aWyYTrP_T0el1eqykO_pQQ', 'name': 'get_weather', 'input': {'location': 'Shanghai, China'}}}]}, {'role': 'user', 'content': [{'toolResult': {'toolUseId': 'tooluse_aWyYTrP_T0el1eqykO_pQQ', 'content': [{'text': '8 degrees Celsius, sunny, good air quality.'}], 'status': 'success'}}]}] {'ResponseMetadata': {'RequestId': 'fb2d8ad1-a8b4-4a85-9c1d-71326e62c3d5', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 21 Mar 2025 03:50:47 GMT', 'content-type': 'application/json', 'content-length': '843', 'connection': 'keep-alive', 'x-amzn-requestid': 'fb2d8ad1-a8b4-4a85-9c1d-71326e62c3d5'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': "Based on the information I've received, here's the current weather in Shanghai:\n\nThe temperature is 8 degrees Celsius (which is about 46 degrees Fahrenheit). The sky is sunny, and the air quality is reported as good.\n\nThis weather is typical for Shanghai during certain times of the year, especially in late autumn or early spring. The sunny conditions and good air quality make it a pleasant day in the city. However, it's relatively cool, so if you're in Shanghai or planning to visit, you might want to wear a light jacket or sweater when going outside.\n\nIs there anything else you'd like to know about the weather in Shanghai or any other location?"}]}}, 'stopReason': 'end_turn', 'usage': {'inputTokens': 485, 'outputTokens': 147, 'totalTokens': 632}, 'metrics': {'latencyMs': 5241}} ``` ### ❌ Actual Behavior _No response_
yindo closed this issue 2026-02-21 19:04:46 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 20, 2025):

@GxWwT Hello! I'm here to help you with bug reports, answer questions, and assist you in becoming a contributor. Let me know how I can assist you with the AWS Bedrock Claude Tooluse Error.

To resolve the AWS Bedrock Claude Tooluse Error stating "The toolConfig field must be defined when using toolUse and toolResult content blocks," ensure that the toolConfig field is included in your requests whenever you use toolUse and toolResult content blocks. This error occurs due to missing tool configurations, and the issue has been addressed in PR #12463 [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] commented on GitHub (Mar 20, 2025): <!-- Greeting --> @GxWwT Hello! I'm here to help you with bug reports, answer questions, and assist you in becoming a contributor. Let me know how I can assist you with the AWS Bedrock Claude Tooluse Error. <!-- Answer --> To resolve the AWS Bedrock Claude Tooluse Error stating "The toolConfig field must be defined when using toolUse and toolResult content blocks," ensure that the `toolConfig` field is included in your requests whenever you use `toolUse` and `toolResult` content blocks. This error occurs due to missing tool configurations, and the issue has been addressed in PR #12463 <sup>[[1]](https://github.com/langgenius/dify/issues/12460)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/4f4451d5-58b1-4187-91d9-eb9a74e60a23?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/4f4451d5-58b1-4187-91d9-eb9a74e60a23?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/4f4451d5-58b1-4187-91d9-eb9a74e60a23?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/4f4451d5-58b1-4187-91d9-eb9a74e60a23?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4f4451d5-58b1-4187-91d9-eb9a74e60a23?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/4f4451d5-58b1-4187-91d9-eb9a74e60a23?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4f4451d5-58b1-4187-91d9-eb9a74e60a23?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Mar 20, 2025):

Can you clarify the Cloud or Self Hosted and Version. Our cloud is current at v1.1.1

@crazywoola commented on GitHub (Mar 20, 2025): Can you clarify the `Cloud or Self Hosted` and `Version`. Our cloud is current at v1.1.1
Author
Owner

@ghost commented on GitHub (Mar 20, 2025):

0.15.3 for Self Hosted

@ghost commented on GitHub (Mar 20, 2025): 0.15.3 for Self Hosted
Author
Owner

@ghost commented on GitHub (Mar 20, 2025):

For v1.1.1, we're facing proxy issues, so we can't upgrade.

@ghost commented on GitHub (Mar 20, 2025): For v1.1.1, we're facing proxy issues, so we can't upgrade.
Author
Owner

@crazywoola commented on GitHub (Mar 20, 2025):

FYI, we won't release a fix for it under 1.0.0.

@crazywoola commented on GitHub (Mar 20, 2025): FYI, we won't release a fix for it under 1.0.0.
Author
Owner

@ghost commented on GitHub (Mar 21, 2025):

I understand, so please check first whether v1.1.1 still has the same issues mentioned above.

@ghost commented on GitHub (Mar 21, 2025): I understand, so please check first whether v1.1.1 still has the same issues mentioned above.
Author
Owner

@crazywoola commented on GitHub (Mar 21, 2025):

Sure, will go back to this thread later.

@crazywoola commented on GitHub (Mar 21, 2025): Sure, will go back to this thread later.
Author
Owner

@ghost commented on GitHub (Mar 24, 2025):

[bedrock] Error: PluginInvokeError: {"args":{"description":"[models] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks."},"error_type":"InvokeError","message":"[models] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks."}

I upgraded dify to the newest version, but still there is toolConfig error. Otherwise I'm really going to have to talk to Lu Yu about this issue.

@ghost commented on GitHub (Mar 24, 2025): [bedrock] Error: PluginInvokeError: {"args":{"description":"[models] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks."},"error_type":"InvokeError","message":"[models] Error: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks."} ### I upgraded dify to the newest version, but still there is toolConfig error. Otherwise I'm really going to have to talk to Lu Yu about this issue.
Author
Owner

@crazywoola commented on GitHub (Mar 24, 2025):

Can you provide the DSL?

Image

I have talked to the AWS Dev team regarding this issue. It seems to be a rare case.

Ref: https://github.com/langgenius/dify/issues/7328

I upgraded dify to the newest version, but still there is toolConfig error. Otherwise I'm really going to have to talk to Lu Yu about this issue.

Talking to him can not solve this issue, while providing correct information and detailed steps can.

"Programmers should do what programmers are supposed to do."

@crazywoola commented on GitHub (Mar 24, 2025): Can you provide the DSL? ![Image](https://github.com/user-attachments/assets/e49014f8-4271-46f3-a47b-088232119787) I have talked to the AWS Dev team regarding this issue. It seems to be a rare case. Ref: https://github.com/langgenius/dify/issues/7328 > I upgraded dify to the newest version, but still there is toolConfig error. Otherwise I'm really going to have to talk to Lu Yu about this issue. Talking to him can not solve this issue, while providing correct information and detailed steps can. "Programmers should do what programmers are supposed to do."
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#11922