Conversation
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 compatibility fix.
Extended reasoning...
Overview
This PR modifies a single file () to add to an existing tuple in . It is a backport of #2434 to the v1.x branch.
Security risks
None. This change only widens an exception catch for schema-generation errors, affecting fallback behavior when a return type is unserializable. No auth, crypto, or permission-sensitive code is touched.
Level of scrutiny
Low. The fix is mechanical: pydantic 2.13 changed 's base class from to , so the existing no longer caught it. Adding explicitly is the correct and minimal fix. The comment is updated to explain the version-specific inheritance difference.
Other factors
No bugs were found by the automated review. The change is covered by an existing test () and exercised by the CI matrix. Single-file, single-concern change with no design decisions to weigh.
Backport of #2434 to
v1.x.Pydantic 2.13.0 changed
PydanticUserError's base class fromTypeErrortoRuntimeError(pydantic/pydantic#12579)._try_create_model_and_schemawas relying onexcept TypeErrorto catchPydanticInvalidForJsonSchemawhen 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
PydanticUserErrorto the except tuple so the fallback works on all supported pydantic versions.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. Thehighestresolution leg of the v1.x CI matrix exercises pydantic 2.13.0 directly.Breaking Changes
None.
Types of changes
Checklist
AI Disclaimer