fix(python): preserve Pydantic field descriptions in schemas - #14454
S.J. (cstolting-collab) wants to merge 1 commit into
Conversation
Summary
Fixes #14443 ValidationBefore this change, a constrained Pydantic field placed Verified after the change:
|
There was a problem hiding this comment.
🟢 Approval recommended
The change is small, targeted, and includes a regression test validating the intended behavior for constrained Pydantic fields.
Pull request overview
This PR updates the Python JSON schema builder to correctly preserve Pydantic field description values when the field also has constraints (e.g., ge/le), and adds a unit test to prevent regressions. This fits into the semantic_kernel schema generation path used to produce structured output schemas from Python/Pydantic models.
Changes:
- Prefer
field_info.descriptionwhen deriving per-field schema descriptions from Pydanticmodel_fields. - Avoid incorrectly treating Pydantic constraint metadata as a field description.
- Add a unit test covering a constrained Pydantic field with a description.
File summaries
| File | Description |
|---|---|
| python/semantic_kernel/schema/kernel_json_schema_builder.py | Adjusts how field descriptions are extracted from Pydantic model_fields to preserve description even when constraints exist. |
| python/tests/unit/schema/test_schema_builder.py | Adds coverage to ensure constrained Pydantic fields keep the intended description in generated schemas. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Motivation and Context
Description
Contribution Checklist