Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

.Net: [Python] KernelJsonSchemaBuilder maps None to JSON "object" in multi-member unions

未关闭 适合新手
#14,482 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@aniketkrs 已经在做这个了。

开始于 2026年9月27日。

  • #14493 来自 @aniketkrs —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

从 semantic_kernel/schema/kernel_json_schema_builder.py 开始,重点查看 TYPE_MAPPING、get_json_schema 以及 handle_complex_type 的 Union 分支。复现 issue 中的多成员 union 案例,然后添加回归测试覆盖,证明 None 应贡献 JSON Schema null 而不是 object,并且生成的函数 schema 能正确处理 nullable 字段。

由索引模型根据 Issue 内容生成。

描述

.NET python triage

Description

KernelJsonSchemaBuilder maps NoneType to JSON type "object" in multi-member unions. A type like int | str | None becomes anyOf: [integer, string, object] instead of including "null".

This breaks function-calling / agent tool schemas for pydantic model parameters: models may emit {} where null/omit was intended.

Distinct from open #14443 (Ge constraint objects in descriptions).

Environment

  • semantic-kernel==1.44.1 (Python)
  • Python 3.13

Minimal repro

import json
from typing import Annotated
from pydantic import BaseModel, Field
from semantic_kernel.connectors.ai.function_calling_utils import (
    kernel_function_metadata_to_function_call_format,
)
from semantic_kernel.functions import KernelPlugin, kernel_function
from semantic_kernel.schema.kernel_json_schema_builder import KernelJsonSchemaBuilder

direct = KernelJsonSchemaBuilder.build(int | str | None)
print(json.dumps(direct))
# {"anyOf": [{"type": "integer"}, {"type": "string"}, {"type": "object"}]}
# null missing; object stand-in for None

class Payload(BaseModel):
    value: int | str | None = Field(default=None, description="flexible")

@kernel_function(name="handle")
def handle(payload: Annotated[Payload, "payload"]) -> str:
    """handle payload"""
    return str(payload)

fn = KernelPlugin(name="P", functions=[handle])["handle"]
fmt = kernel_function_metadata_to_function_call_format(fn.metadata)
print(json.dumps(fmt["function"]["parameters"]["properties"]["payload"]["properties"]["value"]))
# anyOf includes type object for None

Expected

None in unions should map to JSON Schema "null" (or an equivalent nullable form), not "object".

Actual

anyOf includes {"type": "object"} and no "null".

Root cause (pointer)

semantic_kernel/schema/kernel_json_schema_builder.py — TYPE_MAPPING / get_json_schema default "object"; handle_complex_type Union branch only special-cases 2-arg Optional, not multi-member unions containing None.

Suggested fix direction

Map type(None) → {"type": "null"} in TYPE_MAPPING/get_json_schema, and/or strip None from multi-unions into a proper nullable / anyOf+null form.

主要语言
C#
星标
28.7k
派生
4.8k
平均合并
1 天 21 小时
30 天内合并 PR
28

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/semantic-kernel 的其他 Issue

查看 microsoft/semantic-kernel 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。