Python: use field description over pydantic constraint objects in schema builder - #14444
Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
Open
Conversation
…riptions build_model_schema() preferred FieldInfo.metadata over FieldInfo.description when deriving field descriptions. In pydantic v2, FieldInfo.metadata is a list of constraint objects (annotated_types.Ge, Gt, ...), so for any field declared with a constraint (e.g. Field(description=..., ge=0)) the real description was replaced by the constraint object. The resulting schema carried a non-string 'description' and json.dumps() of the function-calling tool payload failed with 'TypeError: Object of type Ge is not JSON serializable'. Only treat str and dict-with-'description' entries in metadata as descriptions (these come from Annotated metadata), and fall back to FieldInfo.description otherwise.
Manohar Paturi (ManoharPaturi)
requested a review
from a team
as a code owner
September 13, 2026 16:46
Manohar Paturi (ManoharPaturi)
had a problem deploying
to
github-app-auth
September 13, 2026 16:46 — with
GitHub Actions
Failure
Manohar Paturi (ManoharPaturi)
had a problem deploying
to
github-app-auth
September 13, 2026 16:46 — with
GitHub Actions
Failure
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14443.
The field-description extraction now only accepts
strmetadata entries (or dicts carrying a description) and falls back tofield_info.description, instead of blindly takingFieldInfo.metadata[0], which under pydantic v2 is a constraint object likeGe(ge=0). Constrained fields keep their real description and the generated schema serializes cleanly.2 regression tests (constrained field keeps description; schema JSON-serializable) fail on main and pass here;
tests/unit/schemagreen, connectors/mcp unaffected (23 passed).