[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.
marked this pull request as ready for review
maxisbey
deleted the
maxisbey/v1.x-pydantic-213-func-metadata
branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters