| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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.
There was a problem hiding this comment.
LGTM — simple, targeted pydantic 2.13 compatibility fix.
Extended reasoning...Single-file change to func_metadata.py: adds PydanticUserError to the import and to the exception tuple in _try_create_model_and_schema. No logic changes beyond the broader catch.
None. This is a narrow exception-handling fix with no auth, crypto, or data-exposure concerns.
Low. The change is mechanical and well-understood: pydantic 2.13 changed PydanticUserError's base from TypeError to RuntimeError, breaking the implicit catch. Catching the named exception explicitly is the correct and idiomatic fix. TypeError is retained for safety.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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 contains a field that can't be represented in JSON Schema (e.g. Callable). On pydantic 2.13.0 that exception now escapes, so registering such a tool crashes instead of falling back to unstructured output.
This adds PydanticUserError to the except tuple so the fallback works on all supported pydantic versions.
Motivation and Context
Without this, on pydantic 2.13.0:
Previously this logged a message and continued with output_schema=None.
How Has This Been Tested?
Covered by the existing test_structured_output_unserializable_type_error, which fails on pydantic 2.13.0 without this change and passes with it. Verified locally on the locked pydantic version; CI will exercise both lowest-direct and the locked version.
Breaking Changes
None.
Types of changes
Checklist
Additional context
PydanticUserError is the parent of both PydanticInvalidForJsonSchema and PydanticSchemaGenerationError and has existed since pydantic 2.0, so catching it is correct regardless of which built-in exception it subclasses in a given pydantic release. TypeError is kept in the tuple to avoid changing behaviour for any other code path that might raise a plain TypeError here.
AI Disclaimer