◐ Shell
clean mode source ↗

[v1.x] fix: catch PydanticUserError when generating output schema (pydantic 2.13 compat) by maxisbey · Pull Request #2435 · modelcontextprotocol/python-sdk

Pydantic 2.13.0 changed PydanticUserError's base class from TypeError to
RuntimeError (pydantic/pydantic#12579). _try_create_model_and_schema was
relying on `except TypeError` to catch PydanticInvalidForJsonSchema when
a return type can't be represented in JSON Schema (e.g. a Callable field).
On pydantic 2.13.0 the exception escapes and tool registration crashes
instead of falling back to unstructured output.

Catch PydanticUserError explicitly so the fallback works regardless of
which built-in exception it subclasses.

@maxisbey marked this pull request as ready for review

April 13, 2026 14:32

claude[bot]

felixweinberger

@maxisbey maxisbey deleted the maxisbey/v1.x-pydantic-213-func-metadata branch

April 13, 2026 16:09