Repository navigation
Python: Build an array schema for frozenset parameters - #14782
Open
Ishkirat Singh (Ishkirat-Singh) wants to merge 1 commit into
Open
Ishkirat Singh (Ishkirat-Singh) wants to merge 1 commit into
Ishkirat Singh (Ishkirat-Singh) wants to merge 1 commit into
Conversation
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.
Ishkirat Singh (Ishkirat-Singh)
requested a review
from a team
as a code owner
November 11, 2026 15:36
Ishkirat Singh (Ishkirat-Singh)
deployed
to
github-app-auth
November 11, 2026 15:36 — with
GitHub Actions
Active
Author
|
@microsoft-github-policy-service agree |
Muhammad Abdullah Butt (1AbdullahButt)
left a comment
There was a problem hiding this comment.
Looks correct. Here's what I checked.
- All three paths reach the new entries.
frozenset[int]has__args__, sobuildsends it tohandle_complex_type, whereget_originreturnsfrozensetand the neworigin in (list, set, frozenset)branch applies. Barefrozensethas neither__annotations__nor__args__, so it falls toget_json_schemaand the newTYPE_MAPPING[frozenset]. The"frozenset"string goes throughbuild_from_type_name.typing.FrozenSet[int]has the same origin, so it's covered too. - Runtime parsing matches the schema.
KernelFunctionFromMethod._parse_parameterhas nofrozensetbranch, so it ends atparam_type(value). Calling the aliasfrozenset[str](["b", "a"])returnsfrozenset({'b', 'a'})(checked in plain Python). A JSON array from the model becomes a frozenset, as the description says. As withset[...], item types aren't coerced on that path, but that's not new. git merge-treeagainstmainis 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
KernelJsonSchemaBuilderturnsset[int]into{"type": "array", "items": {"type": "integer"}}, butfrozenset[int]becomes{"type": "object"}. So a kernel function such asadvertises
tagsto the model as an object, even though_parse_parameterbuilds the frozenset from a list (KernelArguments(tags=["b", "a"])arrives asfrozenset({"a", "b"})). Pydantic also describesfrozenset[str]as an array of strings.Description
frozensetis now handled likeset:handle_complex_typechecksorigin in (list, set, frozenset), andTYPE_MAPPINGgetsfrozenset/"frozenset"entries next toset/"set", so barefrozensetand the type-name path map to"array"too. Nothing else changes.I added
test_build_frozensettotests/unit/schema/test_schema_builder.pyforfrozenset[int], barefrozenset, and the"frozenset"type name. It failed onmain({'type': 'object'}). The function above now reports{'type': 'array', 'items': {'type': 'string'}, 'description': 'tags'}as its parameter schema.pytest tests/unit/schema: 67 passedpytest tests/unit/schema tests/unit/functions tests/unit/kernel tests/unit/prompt_template: 640 passedruff checkandruff format --check(0.15.5, the version inuv.lock) on both files: cleanmypyonkernel_json_schema_builder.py: no issuesContribution Checklist