Skip to content

Python: fix(python): respect type alias and default type in KernelParameterMetadata schema inference - #14705

Open
Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/kernel-parameter-metadata-type-alias
Open

Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/kernel-parameter-metadata-type-alias

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Description

When instantiating KernelParameterMetadata, the parameter type can be provided either via type_="..." or via its declared alias type="..." (or defaulted to "str").

However, form_schema runs as a mode="before" model validator prior to alias resolution and default population in Pydantic. Inside form_schema:

type_ = data.get("type_", None)

This caused two issues:

  1. When callers initialize metadata with the alias type="..." (e.g., KernelParameterMetadata(name="query", type="str")), data contains "type", so data.get("type_") evaluates to None. As a result, infer_schema returns None and metadata.schema_data remains None.
  2. When callers initialize metadata without specifying a type (relying on the default type_: str | None = Field(default="str", alias="type")), type_ is also absent from data during mode="before", leaving metadata.schema_data as None instead of inferring {"type": "string"}.

When tool-calling or function-choice schemas are constructed across connectors (OpenAI, Anthropic, Bedrock, etc.), missing schema_data serializes parameter properties as null instead of their proper JSON schema.

Fix

  • In KernelParameterMetadata.form_schema, check data.get("type_") or data.get("type").
  • If neither was provided and no type_object was specified, fall back to "str" matching the field default.
  • Added regression tests verifying schema inference when using the type alias and when using the default type.

Verification

  • Added regression tests in python/tests/unit/functions/test_kernel_parameter_metadata.py.
  • All unit tests in python/tests/unit/functions/ pass (208 passed).
  • Ruff check and formatting checks pass cleanly.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 17:22
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 1, 2026 17:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Eduard van Valkenburg (@eavanvalkenburg), could you please take a look at this PR when you have a moment? It fixes schema_data inference in KernelParameterMetadata when using the 'type' alias or when relying on the default 'str' type. Tests and ruff checks pass cleanly. Thank you!

@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 1, 2026

This branch was successfully deployed

1 active deployment
github-app-auth — 1bec7b85 Deployed Nov 1, 2026 by hardikkaurani via add_label #29532
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants