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

Author: ManoharPaturiCreated Sep 13, 2026Updated Sep 16, 2026
Labelspythontriage

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

python
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

Source: microsoft/semantic-kernel