microsoft / microsoft/semantic-kernel
Python: build_model_schema puts pydantic constraint objects into field descriptions (breaks tool payload JSON)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 28.6k
- Forks
- 4.8k
- Avg merge
- 14h 13m
- Merged PRs (30d)
- 18
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
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.
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.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100