microsoft / microsoft/semantic-kernel

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

Open Beginner friendly
#14,441 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

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

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.

Research direction

Start in semantic_kernel/functions/kernel_function_decorator.py at _parse_parameter(), then run the reproduction from the issue with two functions sharing Annotated metadata. Done means decoration leaves caller-owned metadata unchanged and both functions retain the description; add or update a regression test if the surrounding test structure identifies a suitable location.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.