Skip to content

Python: Build an array schema for frozenset parameters - #14782

Open
Ishkirat Singh (Ishkirat-Singh) wants to merge 1 commit into
microsoft:mainfrom
Ishkirat-Singh:fix/schema-builder-frozenset
Open

Ishkirat Singh (Ishkirat-Singh) wants to merge 1 commit into
microsoft:mainfrom
Ishkirat-Singh:fix/schema-builder-frozenset

Conversation

@Ishkirat-Singh

Copy link
Copy Markdown

Motivation and Context

KernelJsonSchemaBuilder turns set[int] into {"type": "array", "items": {"type": "integer"}}, but frozenset[int] becomes {"type": "object"}. So a kernel function such as

@kernel_function
def tag(self, tags: Annotated[frozenset[str], "tags"]) -> str: ...

advertises tags to the model as an object, even though _parse_parameter builds the frozenset from a list (KernelArguments(tags=["b", "a"]) arrives as frozenset({"a", "b"})). Pydantic also describes frozenset[str] as an array of strings.

Description

frozenset is now handled like set: handle_complex_type checks origin in (list, set, frozenset), and TYPE_MAPPING gets frozenset / "frozenset" entries next to set / "set", so bare frozenset and the type-name path map to "array" too. Nothing else changes.

I added test_build_frozenset to tests/unit/schema/test_schema_builder.py for frozenset[int], bare frozenset, and the "frozenset" type name. It failed on main ({'type': 'object'}). The function above now reports {'type': 'array', 'items': {'type': 'string'}, 'description': 'tags'} as its parameter schema.

  • pytest tests/unit/schema: 67 passed
  • pytest tests/unit/schema tests/unit/functions tests/unit/kernel tests/unit/prompt_template: 640 passed
  • ruff check and ruff format --check (0.15.5, the version in uv.lock) on both files: clean
  • mypy on kernel_json_schema_builder.py: no issues

Contribution Checklist

KernelJsonSchemaBuilder mapped set[T] to an array of T but had no case for
frozenset, so frozenset[T] (and bare frozenset) fell through to the
default {"type": "object"}. Function calling then advertised an object
for a parameter that the method parses from a list.
Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:36

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.

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

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks correct. Here's what I checked.

  • All three paths reach the new entries. frozenset[int] has __args__, so build sends it to handle_complex_type, where get_origin returns frozenset and the new origin in (list, set, frozenset) branch applies. Bare frozenset has neither __annotations__ nor __args__, so it falls to get_json_schema and the new TYPE_MAPPING[frozenset]. The "frozenset" string goes through build_from_type_name. typing.FrozenSet[int] has the same origin, so it's covered too.
  • Runtime parsing matches the schema. KernelFunctionFromMethod._parse_parameter has no frozenset branch, so it ends at param_type(value). Calling the alias frozenset[str](["b", "a"]) returns frozenset({'b', 'a'}) (checked in plain Python). A JSON array from the model becomes a frozenset, as the description says. As with set[...], item types aren't coerced on that path, but that's not new.
  • git merge-tree against main is clean.

I didn't run the test suite.

Optional, for both set and frozenset: "uniqueItems": true would tell the model that duplicates collapse. That changes the set schema too, though, so it's probably a separate PR.

Reviewed with help from Claude Code.

This branch was successfully deployed

1 active deployment
github-app-auth — ab5e86d4 Deployed Nov 11, 2026 by Ishkirat-Singh via add_label #29669
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.

3 participants