High severity intermediate · Fix: 2-5 min

ValueError

anthropic.client.exceptions.ValueError

What this error means
Anthropic's client rejects the tool use call because the input_schema provided is invalid or does not conform to the expected JSON schema format.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    response = client.messages.create(
  File "/usr/local/lib/python3.9/site-packages/anthropic/client.py", line 210, in create
    raise ValueError('Invalid input_schema: must be a valid JSON schema dict')
ValueError: Invalid input_schema: must be a valid JSON schema dict
QUICK FIX
Pass a valid JSON schema dict with required keys and correct types as input_schema to client.messages.create.

Why it happens

Anthropic's function-calling feature requires the input_schema parameter to be a valid JSON schema dictionary describing the expected input structure. If the schema is malformed, missing required fields, or not a dict, the client raises this ValueError to prevent sending invalid tool use calls.

Detection

Validate your input_schema against JSON schema standards before calling client.messages.create; log or assert the schema structure to catch errors early.

Causes & fixes

1

input_schema is not a dictionary but a string or other type

✓ Fix

Ensure input_schema is a Python dict representing the JSON schema, not a JSON string or other type.

2

input_schema missing required JSON schema keys like 'type' or 'properties'

✓ Fix

Add required keys such as 'type': 'object' and 'properties' with field definitions to the input_schema dict.

3

input_schema fields have invalid types or unsupported schema constructs

✓ Fix

Use only supported JSON schema types and constructs as per Anthropic's documentation; validate schema with a JSON schema validator.

4

Passing input_schema as None or empty dict

✓ Fix

Provide a fully defined JSON schema dict describing the expected input fields instead of None or {}.

Code: broken vs fixed

Broken - triggers the error
python
from anthropic import Anthropic
import os

client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

# Broken: input_schema is a JSON string, not dict
response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    system="You are a helpful assistant.",
    messages=[{"role": "user", "content": "Call tool with data."}],
    tool_use={
        "name": "my_tool",
        "input_schema": '{"type": "object", "properties": {"query": {"type": "string"}}}'  # invalid
    }
)  # This line raises ValueError
Fixed - works correctly
python
from anthropic import Anthropic
import os

client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

# Fixed: input_schema is a dict, not a string
response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    system="You are a helpful assistant.",
    messages=[{"role": "user", "content": "Call tool with data."}],
    tool_use={
        "name": "my_tool",
        "input_schema": {
            "type": "object",
            "properties": {
                "query": {"type": "string"}
            },
            "required": ["query"]
        }  # Changed to dict with required keys
    }
)
print(response)  # Shows successful response
Changed input_schema from a JSON string to a properly structured Python dict with required JSON schema keys, satisfying Anthropic's validation.

Workaround

Catch the ValueError exception around client.messages.create, then manually validate or fix the input_schema before retrying the call.

Prevention

Always define and validate your input_schema as a proper JSON schema dict before passing it to Anthropic's tool_use parameter to avoid runtime validation errors.

Python 3.9+ · anthropic >=0.20.0 · tested on 0.20.x
Verified 2026-04
Verify ↗

Community Notes

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