Skip to content

Python: @kernel_function mutates shared Annotated metadata dicts (description lost after first use) #14441

Description

Description

@kernel_function's _parse_parameter() calls meta.pop("description") on dict metadata inside typing.Annotated, mutating the caller's dict. Reusing one shared metadata dict across kernel functions silently strips the parameter description from every function after the first, and leaves the user's dict empty.

Reproduction

from typing import Annotated
from semantic_kernel.functions.kernel_function_decorator import kernel_function
from semantic_kernel.functions import KernelFunctionFromMethod

shared = {"description": "the answer count"}

@kernel_function
def a(x: Annotated[int, shared]) -> int: ...

@kernel_function
def b(y: Annotated[int, shared]) -> int: ...

KernelFunctionFromMethod(a, "a").metadata.parameters[0].description  # 'the answer count'
KernelFunctionFromMethod(b, "b").metadata.parameters[0].description  # None  <-- lost
shared  # {}  <-- caller's dict mutated

Expected behavior

Decoration never mutates caller-owned metadata; both functions see the description.

Environment

semantic-kernel python main (ca40aa72), Python 3.12

Activity

  1. nslabhwan commented on Sep 16, 2026

    @nslabhwan

    I reproduced this on current main. _parse_parameter() mutates caller-owned Annotated dict metadata via meta.pop("description"), so reusing the same metadata dict loses the description after the first decoration. I'm taking this issue with a focused fix that copies the metadata dict before parsing and a regression test covering reuse across two @kernel_function decorators. Targeted function tests and Ruff checks are passing; I'll open a small PR.

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