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

Open Beginner friendly
#14,443 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api

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

python triage
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

Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
14h 13m
Merged PRs (30d)
18

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/semantic-kernel

All issues in microsoft/semantic-kernel

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.