High severity beginner · Fix: 2-5 min

ValueError

builtins.ValueError

What this error means
AWS Bedrock converse API tool use calls fail with JSON parsing errors due to malformed or unexpected JSON in the tool input or output.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    response = client.bedrock_runtime.invoke_model(
  File "/usr/local/lib/python3.9/site-packages/boto3/client.py", line 530, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 984, in _make_api_call
    raise error_class(parsed_response['Error']['Message'])
ValueError: Expecting value: line 1 column 1 (char 0)
QUICK FIX
Use json.dumps() to serialize the tool input dict before passing it to the Bedrock converse API call.

Why it happens

The AWS Bedrock converse API expects the 'toolInput' parameter to be a valid JSON string. If the input is malformed, empty, or not properly serialized, the API returns an error when attempting to parse it. Similarly, if the response contains unexpected or invalid JSON, parsing fails. This often happens when the developer passes a Python dict directly without JSON serialization or includes extra characters.

Detection

Validate and log the 'toolInput' JSON string before sending the request. Use try/except around JSON serialization and API calls to catch ValueError and log raw inputs and outputs for debugging.

Causes & fixes

1

Passing a Python dict directly as 'toolInput' instead of a JSON string

✓ Fix

Serialize the dict to a JSON string using json.dumps() before passing it to the 'toolInput' parameter.

2

Including trailing commas or comments in the JSON string causing invalid JSON

✓ Fix

Ensure the JSON string is strictly valid by removing trailing commas and comments before sending.

3

Empty or None value passed as 'toolInput' causing parsing failure

✓ Fix

Always pass a non-empty valid JSON string; if no input is needed, pass '{}' as the JSON string.

4

Response from Bedrock contains unexpected non-JSON content or is empty

✓ Fix

Add error handling to check response content before JSON parsing and log raw response for troubleshooting.

Code: broken vs fixed

Broken - triggers the error
python
import boto3

client = boto3.client('bedrock-runtime')

input_data = {'query': 'Hello'}
response = client.invoke_model(
    modelId='my-model',
    contentType='application/json',
    accept='application/json',
    body={"toolInput": input_data}  # This line causes ValueError
)
print(response)
Fixed - works correctly
python
import os
import json
import boto3

client = boto3.client('bedrock-runtime',
                      aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
                      aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
                      region_name=os.environ.get('AWS_REGION', 'us-east-1'))

input_data = {'query': 'Hello'}
json_input = json.dumps(input_data)  # Serialize dict to JSON string
response = client.invoke_model(
    modelId='my-model',
    contentType='application/json',
    accept='application/json',
    body={"toolInput": json_input}  # Fixed: pass JSON string
)
print(response)
Added json.dumps() to serialize the Python dict to a JSON string before passing it as 'toolInput', preventing JSON parsing errors.

Workaround

Wrap the API call in try/except catching ValueError; on failure, log the raw 'toolInput' and response content, then manually parse JSON with error-tolerant methods or retry with corrected input.

Prevention

Always serialize tool input data to valid JSON strings before API calls and validate JSON format with linters or schema validators to avoid malformed payloads.

Python 3.9+ · boto3 >=1.26.0 · tested on 1.28.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.