From 1bd9c1a0c6619429b130ea04a89c5304f102a442 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 15 Nov 2026 17:07:31 +0530 Subject: [PATCH 1/7] test(schema): add failing test for Sequence and MutableSequence parameter schemas --- python/tests/unit/schema/test_schema_builder.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python/tests/unit/schema/test_schema_builder.py b/python/tests/unit/schema/test_schema_builder.py index 5f9687d010b2..f649532cbd75 100644 --- a/python/tests/unit/schema/test_schema_builder.py +++ b/python/tests/unit/schema/test_schema_builder.py @@ -1,6 +1,7 @@ # Copyright (c) Microsoft. All rights reserved. import json +from collections.abc import MutableSequence, Sequence from enum import Enum from typing import Annotated, Any, ClassVar, Literal, Optional, Union from unittest.mock import Mock @@ -251,6 +252,16 @@ def test_build_optional_variadic_tuple(): assert schema == {"type": ["array", "null"], "items": {"type": "string"}} +def test_build_sequence(): + schema = KernelJsonSchemaBuilder.build(Sequence[int], "items") + assert schema == {"type": "array", "items": {"type": "integer"}, "description": "items"} + + +def test_build_mutable_sequence(): + schema = KernelJsonSchemaBuilder.build(MutableSequence[str]) + assert schema == {"type": "array", "items": {"type": "string"}} + + def test_build_union(): schema = KernelJsonSchemaBuilder.build(Union[int, str]) assert schema == {"anyOf": [{"type": "integer"}, {"type": "string"}]} From a8bed5e63ca4cb24aab123b8af77b6f0d7e1afd1 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 15 Nov 2026 17:10:03 +0530 Subject: [PATCH 2/7] fix(schema): support collections.abc Sequence and MutableSequence in KernelJsonSchemaBuilder --- .../semantic_kernel/schema/kernel_json_schema_builder.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/semantic_kernel/schema/kernel_json_schema_builder.py b/python/semantic_kernel/schema/kernel_json_schema_builder.py index 5a2e2c0200a4..71742610ad99 100644 --- a/python/semantic_kernel/schema/kernel_json_schema_builder.py +++ b/python/semantic_kernel/schema/kernel_json_schema_builder.py @@ -2,6 +2,7 @@ import sys import types +from collections.abc import MutableSequence, Sequence from enum import Enum from typing import Any, ClassVar, Literal, Union, get_args, get_origin, get_type_hints @@ -54,10 +55,10 @@ def build( return cls.build_model_schema(parameter_type, description, structured_output) if isinstance(parameter_type, type) and issubclass(parameter_type, Enum): return cls.build_enum_schema(parameter_type, description) + if get_origin(parameter_type) is not None or hasattr(parameter_type, "__args__"): + return cls.handle_complex_type(parameter_type, description, structured_output) if hasattr(parameter_type, "__annotations__"): return cls.build_model_schema(parameter_type, description, structured_output) - if hasattr(parameter_type, "__args__"): - return cls.handle_complex_type(parameter_type, description, structured_output) schema = cls.get_json_schema(parameter_type) if description: schema["description"] = description @@ -182,7 +183,7 @@ def handle_complex_type( args = get_args(parameter_type) schema: dict[str, Any] = {} - if origin is list or origin is set: + if origin is list or origin is set or origin is Sequence or origin is MutableSequence: item_type = args[0] schema = { "type": "array", From 86fbe76d70a0eab7427683150cbba4f9f86fe4d6 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 15 Nov 2026 17:10:39 +0530 Subject: [PATCH 3/7] test(schema): add failing test for Mapping and MutableMapping parameter schemas --- .../tests/unit/schema/test_schema_builder.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/python/tests/unit/schema/test_schema_builder.py b/python/tests/unit/schema/test_schema_builder.py index f649532cbd75..5460409cc111 100644 --- a/python/tests/unit/schema/test_schema_builder.py +++ b/python/tests/unit/schema/test_schema_builder.py @@ -1,7 +1,7 @@ # Copyright (c) Microsoft. All rights reserved. import json -from collections.abc import MutableSequence, Sequence +from collections.abc import Mapping, MutableMapping, MutableSequence, Sequence from enum import Enum from typing import Annotated, Any, ClassVar, Literal, Optional, Union from unittest.mock import Mock @@ -262,6 +262,23 @@ def test_build_mutable_sequence(): assert schema == {"type": "array", "items": {"type": "string"}} +def test_build_mapping(): + schema = KernelJsonSchemaBuilder.build(Mapping[str, int], "counts") + assert schema == { + "type": "object", + "additionalProperties": {"type": "integer"}, + "description": "counts", + } + + +def test_build_mutable_mapping(): + schema = KernelJsonSchemaBuilder.build(MutableMapping[str, float]) + assert schema == { + "type": "object", + "additionalProperties": {"type": "number"}, + } + + def test_build_union(): schema = KernelJsonSchemaBuilder.build(Union[int, str]) assert schema == {"anyOf": [{"type": "integer"}, {"type": "string"}]} From d2772eee3836acac6e11b083ed4dc118c7e7c38e Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 15 Nov 2026 17:11:38 +0530 Subject: [PATCH 4/7] fix(schema): support collections.abc Mapping and MutableMapping in KernelJsonSchemaBuilder --- python/semantic_kernel/schema/kernel_json_schema_builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/semantic_kernel/schema/kernel_json_schema_builder.py b/python/semantic_kernel/schema/kernel_json_schema_builder.py index 71742610ad99..a64f311a404f 100644 --- a/python/semantic_kernel/schema/kernel_json_schema_builder.py +++ b/python/semantic_kernel/schema/kernel_json_schema_builder.py @@ -2,7 +2,7 @@ import sys import types -from collections.abc import MutableSequence, Sequence +from collections.abc import Mapping, MutableMapping, MutableSequence, Sequence from enum import Enum from typing import Any, ClassVar, Literal, Union, get_args, get_origin, get_type_hints @@ -192,7 +192,7 @@ def handle_complex_type( if description: schema["description"] = description return schema - if origin is dict: + if origin is dict or origin is Mapping or origin is MutableMapping: _, value_type = args additional_properties = cls.build(value_type, structured_output=structured_output) if additional_properties == {"type": "object"}: From 47b63535f46744df0b798d02d4b217bbe822ef5f Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 15 Nov 2026 17:12:07 +0530 Subject: [PATCH 5/7] test(schema): verify Optional and Union wrappers with Sequence and Mapping --- python/tests/unit/schema/test_schema_builder.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/tests/unit/schema/test_schema_builder.py b/python/tests/unit/schema/test_schema_builder.py index 5460409cc111..aed516abf39a 100644 --- a/python/tests/unit/schema/test_schema_builder.py +++ b/python/tests/unit/schema/test_schema_builder.py @@ -279,6 +279,16 @@ def test_build_mutable_mapping(): } +def test_build_optional_sequence(): + schema = KernelJsonSchemaBuilder.build(Optional[Sequence[int]]) + assert schema == {"type": ["array", "null"], "items": {"type": "integer"}} + + +def test_build_optional_mapping(): + schema = KernelJsonSchemaBuilder.build(Optional[Mapping[str, str]]) + assert schema == {"type": ["object", "null"], "additionalProperties": {"type": "string"}} + + def test_build_union(): schema = KernelJsonSchemaBuilder.build(Union[int, str]) assert schema == {"anyOf": [{"type": "integer"}, {"type": "string"}]} From e945592f7e5ae2c1f7e1d00cb8680fcadaa87d0b Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 15 Nov 2026 17:12:57 +0530 Subject: [PATCH 6/7] docs(schema): document Sequence and Mapping support in handle_complex_type docstring --- python/semantic_kernel/schema/kernel_json_schema_builder.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/semantic_kernel/schema/kernel_json_schema_builder.py b/python/semantic_kernel/schema/kernel_json_schema_builder.py index a64f311a404f..67a0c90a5a0b 100644 --- a/python/semantic_kernel/schema/kernel_json_schema_builder.py +++ b/python/semantic_kernel/schema/kernel_json_schema_builder.py @@ -171,6 +171,9 @@ def handle_complex_type( ) -> dict[str, Any]: """Handles building the JSON schema for complex types. + Supports standard generic containers including list, set, Sequence, + MutableSequence, dict, Mapping, MutableMapping, tuple, Literal, and Union. + Args: parameter_type: The parameter type. description: The description of the parameter. Defaults to None. From 2cef06f196ed7734072f593173599d65ad0bb16b Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sun, 15 Nov 2026 17:13:49 +0530 Subject: [PATCH 7/7] test(schema): verify description and structured_output with Sequence and Mapping --- python/tests/unit/schema/test_schema_builder.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/tests/unit/schema/test_schema_builder.py b/python/tests/unit/schema/test_schema_builder.py index aed516abf39a..e531b6d8b56d 100644 --- a/python/tests/unit/schema/test_schema_builder.py +++ b/python/tests/unit/schema/test_schema_builder.py @@ -289,6 +289,22 @@ def test_build_optional_mapping(): assert schema == {"type": ["object", "null"], "additionalProperties": {"type": "string"}} +def test_build_sequence_and_mapping_with_structured_output(): + seq_schema = KernelJsonSchemaBuilder.build(Sequence[str], description="a list of names", structured_output=True) + assert seq_schema == { + "type": "array", + "items": {"type": "string"}, + "description": "a list of names", + } + + map_schema = KernelJsonSchemaBuilder.build(Mapping[str, int], description="lookup table", structured_output=True) + assert map_schema == { + "type": "object", + "additionalProperties": False, + "description": "lookup table", + } + + def test_build_union(): schema = KernelJsonSchemaBuilder.build(Union[int, str]) assert schema == {"anyOf": [{"type": "integer"}, {"type": "string"}]}