You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: build_model_schema puts pydantic constraint objects into field descriptions (breaks tool payload JSON) #14443
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 Ge object and fails JSON serialization with TypeError: Object of type Ge is not JSON serializable, breaking function-calling payloads for OpenAI-compatible connectors
frompydanticimportBaseModel, Fieldimportjsonfromsemantic_kernel.schema.kernel_json_schema_builderimportKernelJsonSchemaBuilderclassParams(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
Activity