Skip to content

fix(python): preserve Pydantic field descriptions in schemas - #14454

Open
S.J. (cstolting-collab) wants to merge 1 commit into
microsoft:mainfrom
cstolting-collab:fix/pydantic-field-description-schema
Open

S.J. (cstolting-collab) wants to merge 1 commit into
microsoft:mainfrom
cstolting-collab:fix/pydantic-field-description-schema

Conversation

@cstolting-collab

@cstolting-collab S.J. (cstolting-collab) commented Sep 17, 2026

Copy link
Copy Markdown

Motivation and Context

Description

Contribution Checklist

@cstolting-collab

Copy link
Copy Markdown
Author

Summary

  • Prefer Pydantic FieldInfo.description when building model field schemas.
  • Preserve the existing metadata-dictionary fallback for compatibility.
  • Add a regression test for constrained Pydantic fields.

Fixes #14443

Validation

Before this change, a constrained Pydantic field placed Ge(ge=0.0) in the generated schema description, causing json.dumps() to raise TypeError.

Verified after the change:

  • uv run pytest tests/unit/schema/test_schema_builder.py — 37 passed
  • `uv run pre-commit run --files semantic_kernel/schema/kernel_json_schema_builder.py tests/unit/schema/tes

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.

🟢 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.description when deriving per-field schema descriptions from Pydantic model_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.

This branch had an error being deployed

1 failed deployment
github-app-auth 64b49429 Deployed Sep 17, 2026 by cstolting-collab via review #519
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.

2 participants