Skip to content

Python: fix(functions): validate complex kernel function arguments - #14466

Open
Adil Alperen Çiftci (adilalperenciftci) wants to merge 5 commits into
microsoft:mainfrom
adilalperenciftci:fix/validate-complex-kernel-arguments
Open

Adil Alperen Çiftci (adilalperenciftci) wants to merge 5 commits into
microsoft:mainfrom
adilalperenciftci:fix/validate-complex-kernel-arguments

Conversation

@adilalperenciftci

@adilalperenciftci Adil Alperen Çiftci (adilalperenciftci) commented Sep 21, 2026 •

Copy link
Copy Markdown

Summary

Complex and union annotations containing commas could skip parameter validation in gather_function_parameters, allowing values with the wrong shape to reach the kernel function. PEP 604 unions also needed their original annotation preserved when non-optional type resolution returned no entries.

Changes

  • Validate generic and union annotations with Pydantic TypeAdapter.
  • Remove the comma-based condition that skipped parsing for complex type metadata.
  • Preserve the original union annotation when non-optional type resolution is empty.
  • Permit ordinary custom Python classes while retaining rejection of invalid values.
  • Add regression coverage for valid and invalid dict[str, int] inputs, invalid union inputs, valid primitive branches, and valid custom-class instances.

Validation

  • Focused function suites: 117 passed on Python 3.12.
  • Ruff checks and formatting checks pass for all changed files.

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 reached their quota limit.

@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 10, 2026
@github-actions github-actions Bot changed the title fix(functions): validate complex kernel function arguments Python: fix(functions): validate complex kernel function arguments Oct 10, 2026
@adilalperenciftci

Copy link
Copy Markdown
Author

Updated the branch to current main. The focused validation suite passes 43 tests; Ruff check and formatting checks are also clean. Could a maintainer approve the workflows and take a first look at the new head?

Complex and Union annotations containing commas could skip parameter parsing in
gather_function_parameters, allowing raw argument values to reach the kernel
function. Validate generic annotations with Pydantic TypeAdapter so malformed
values are rejected before invocation.

Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
… empty

Preserve PEP 604 and typing.Union type metadata during kernel function
parameter inspection when unions do not contain NoneType.

Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
TypeAdapter rejected unions that include ordinary Python classes before
validating the selected branch, so a valid str or custom instance passed to
a parameter annotated Custom | str raised FunctionExecutionException.
Configure the adapter with arbitrary_types_allowed and add regressions for
the valid primitive, the valid custom instance, and the still-rejected
invalid argument.

Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
@adilalperenciftci

Copy link
Copy Markdown
Author

I rebased the branch onto current main and retained the arbitrary-class union regression coverage. The focused function suites pass 115 tests on Python 3.12, and ruff is clean for the changed files. I also resolved the addressed review thread.

@agammann Ammann Labs (agammann) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Removing the comma guard should validate generic annotations such as dict[str, int], but the new tests only exercise unions. Could the regression suite pass one valid and one invalid value to a function with a dict[str, int] argument? That would cover the previously skipped comma path and the new TypeAdapter branch directly.

Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
@adilalperenciftci

Copy link
Copy Markdown
Author

Added the requested valid and invalid dict[str, int] invocation regressions in f678753. The invalid case reproduces the previous comma-path behavior by showing that the function was invoked instead of rejecting the value; the current path raises before invocation. The focused function suites now pass 117 tests on Python 3.12, and Ruff check/format validation is clean.

This branch was successfully deployed

1 active deployment
github-app-auth — f678753f Deployed Nov 11, 2026 by adilalperenciftci via add_label #29668
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.

4 participants