Skip to content

Python: use field description over pydantic constraint objects in schema builder - #14444

Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/schema-builder-field-description
Open

Python: use field description over pydantic constraint objects in schema builder#14444
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/schema-builder-field-description

Conversation

@ManoharPaturi

Copy link
Copy Markdown

Fixes #14443.

The field-description extraction now only accepts str metadata entries (or dicts carrying a description) and falls back to field_info.description, instead of blindly taking FieldInfo.metadata[0], which under pydantic v2 is a constraint object like Ge(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/schema green, connectors/mcp unaffected (23 passed).

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: build_model_schema puts pydantic constraint objects into field descriptions (breaks tool payload JSON)

2 participants