Skip to content

Python: build_model_schema puts pydantic constraint objects into field descriptions (breaks tool payload JSON) #14443

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:

  1. the real Field(..., description=...) is lost from the tool schema
  2. 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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonPull requests for the Python Semantic Kerneltriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions