Python: build_model_schema puts pydantic constraint objects into field descriptions (breaks tool payload JSON)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start in semantic_kernel/schema/kernel_json_schema_builder.py at KernelJsonSchemaBuilder.build_model_schema(), then run the provided Params reproduction with json.dumps. Ensure constraint-only metadata is not used as a description and that field_info.description is preserved; the resulting property schema should remain JSON-serializable.
Written by the indexing model from the issue text.
Description
Description
KernelJsonSchemaBuilder.build_model_schema() puts FieldInfo.metadata[0] into the field's description when a pydantic v2 field has constraints. In pydantic v2, metadata[0] is a constraint object (Ge(ge=0.0)), not a description, so:
- the real
Field(..., description=...)is lost from the tool schema - the resulting schema dict contains a
Geobject and fails JSON serialization withTypeError: Object of type Ge is not JSON serializable, breaking function-calling payloads for OpenAI-compatible connectors
Regression introduced by #6469.
Reproduction
from pydantic import BaseModel, Field
import json
from semantic_kernel.schema.kernel_json_schema_builder import KernelJsonSchemaBuilder
class Params(BaseModel):
top_p: float = Field(default=0.9, ge=0.0, le=1.0, description="nucleus sampling")
json.dumps(KernelJsonSchemaBuilder.build_model_schema(Params)["properties"]["top_p"])
# TypeError: Object of type Ge is not JSON serializable
Expected behavior
Constraint-only metadata is ignored for descriptions; field_info.description is used when present, so the schema stays JSON-serializable.
Environment
semantic-kernel python main (ca40aa72), pydantic v2, Python 3.12
- Dominant language
- C#
- Stars
- 28.6k
- Forks
- 4.8k
- Avg merge
- 14h 13m
- Merged PRs (30d)
- 18
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/semantic-kernel
-
python triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/semantic-kernel#14460 ·
-
Python: @kernel_function mutates shared Annotated metadata dicts (description lost after first use) Openpython triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/semantic-kernel#14441 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microsoft/semantic-kernel#14359 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microsoft/semantic-kernel#14347 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/semantic-kernel#14311 · 2 comments ·
All issues in microsoft/semantic-kernel
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·