Casting to InputSchema drops $defs, causing an InternalServerError
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
Solution: Casting to InputSchema drops $defs, causing an InternalServerError
Thanks for reporting this, and sorry for the problem. We'll look into it soon.
Trust Score
1 verification
- 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
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep