FG
💻 Software🤖 AI & LLMsAnthropic

Casting to InputSchema drops $defs, causing an InternalServerError

Freshalmost 2 years ago
Mar 14, 20260 views
Confidence Score85%
85%

Problem

Consider a tool-calling request with the following schema: [code block] Anthropic correctly handles this so long as `$defs` is present; should it be dropped, the `enum` fields become unresolvable, causing an error of the form of: [code block] Unfortunately, using `pydantic.TypeAdapter(anthropic.types.beta.tools.tool_param.InputSchema).validate_python(tool.model_json_schema())` drops the `$defs` field from the representation -- after getting the aforementioned HTTP 500 error, if we walk the stack up to `anthropic._base_client.post`, we see a body where `$defs` is not present at all, despite references to it existing: [code block] ...thus explaining the HTTP 500. And, indeed, if the use of `pydantic.TypeAdapter(InputSchema).validate_python(tool.model_json_schema())` is replaced with `typing.cast(InputSchema, tool.model_json_schema())`, the issue is resolved. This is unfortunate: Users of this library should not need to give up type safety to avoid triggering server-side errors.

Error Output

error of the form of:

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: Casting to InputSchema drops $defs, causing an InternalServerError

Low Risk

Thanks for reporting this, and sorry for the problem. We'll look into it soon.

84

Trust Score

1 verification

100% success
  1. 1

    Thanks for reporting this, and sorry for the problem. We'll look into it soon.

    Thanks for reporting this, and sorry for the problem. We'll look into it soon.

Validation

Resolved in anthropics/anthropic-sdk-python GitHub issue #485. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

claudeanthropicllmapi