Skip to content

.Net: Python: Bug: ClassVar annotations become required fields in generated tool schemas #14527

Description

@hulkbig

Describe the bug

KernelJsonSchemaBuilder includes ClassVar annotations in the instance schema. A class constant becomes a required object-valued input even though Pydantic excludes it from model fields and serialized instances. This also reaches KernelParameterMetadata, generated function-call tool definitions, and schemas built with structured_output=True.

To Reproduce

Run this module-level example with the environment below:

from typing import ClassVar

from semantic_kernel.functions.kernel_parameter_metadata import KernelParameterMetadata
from semantic_kernel.kernel_pydantic import KernelBaseModel


class Payload(KernelBaseModel):
    marker: ClassVar[str] = "constant"
    value: int


print(Payload(value=1).model_dump())
print(KernelParameterMetadata(name="payload", type_object=Payload).schema_data)

Actual output:

{'value': 1}
{'type': 'object',
 'properties': {'marker': {'type': 'object'}, 'value': {'type': 'integer'}},
 'required': ['marker', 'value']}

Expected behavior

Only instance fields should appear in the schema. Expected schema:

{'type': 'object',
 'properties': {'value': {'type': 'integer'}},
 'required': ['value']}

The generated schema rejects the valid serialized payload {'value': 1} because marker is required. The same behavior reproduces with an inherited ClassVar and with an annotated plain Python class.

Platform

  • Language/source: Semantic Kernel Python 1.44.1, source commit 9974625ddc1e1d3f55e095420fcabcc9329f7f34
  • Python 3.12.14, Pydantic 2.13.5, Linux x86_64
  • AI model: none; no credentials or service requests are needed
  • IDE: not applicable; command-line reproduction

Additional context

Verification

  • Existing schema-builder and parameter-metadata tests: 43 passed
  • Added local regression cases: 14 fail on the unchanged implementation; 4 ordinary-field/plain-class controls pass
  • The combined run gives 14 failed and 47 passed with outbound networking disabled

No production fix has been written or tested, and the full unit and integration suites have not been run.

Proposed bounded scope / coordination

I would like to take on a small test-first compatibility fix that excludes ClassVar annotations from instance-schema properties and required fields while preserving ordinary annotated fields and plain-class support. I would keep forward-reference resolution, field-description handling, and recursive-schema changes out of scope.

I found the adjacent builder work in #14241, #14310, #14454, and #14198. This case appears separate, but the code area overlaps. Would you prefer a standalone fix, or coordination with one of those changes? Given the transition to Microsoft Agent Framework, please also confirm that this limited Semantic Kernel maintenance fix is wanted before I implement it.

AI assistance was used to investigate the bug, prepare the local regression cases, and draft this report.

Activity

  1. added
    .NETIssue or Pull requests regarding .NET code
    pythonPull requests for the Python Semantic Kernel
    on Oct 2, 2026
  2. changed the title [-]Python: Bug: ClassVar annotations become required fields in generated tool schemas[/-] [+].Net: Python: Bug: ClassVar annotations become required fields in generated tool schemas[/+] on Oct 2, 2026
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

    .NETIssue or Pull requests regarding .NET codepythonPull 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