From 990c1b88f54e1dd60e174889dea014e4ec04b3f2 Mon Sep 17 00:00:00 2001 From: Anish Mehta Date: Fri, 30 Oct 2026 19:26:24 +0530 Subject: [PATCH] Python: Build an array schema for variadic tuple parameters --- .../schema/kernel_json_schema_builder.py | 8 ++++++-- python/tests/unit/schema/test_schema_builder.py | 10 ++++++++++ 2 files changed, 16 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 4b6503d09bde..f11a84213e2f 100644 --- a/python/semantic_kernel/schema/kernel_json_schema_builder.py +++ b/python/semantic_kernel/schema/kernel_json_schema_builder.py @@ -196,8 +196,12 @@ def handle_complex_type( schema["additionalProperties"] = False return schema if origin is tuple: - items = [cls.build(arg, structured_output=structured_output) for arg in args] - schema = {"type": "array", "items": items} + if len(args) == 2 and args[1] is Ellipsis: + # tuple[X, ...] holds any number of X, like list[X] + schema = {"type": "array", "items": cls.build(args[0], structured_output=structured_output)} + else: + items = [cls.build(arg, structured_output=structured_output) for arg in args] + schema = {"type": "array", "items": items} if description: schema["description"] = description if structured_output: diff --git a/python/tests/unit/schema/test_schema_builder.py b/python/tests/unit/schema/test_schema_builder.py index 9e7c91ee76e6..1fef1a8f8731 100644 --- a/python/tests/unit/schema/test_schema_builder.py +++ b/python/tests/unit/schema/test_schema_builder.py @@ -241,6 +241,16 @@ def test_build_tuple(): } +def test_build_variadic_tuple(): + schema = KernelJsonSchemaBuilder.build(tuple[int, ...], "ids") + assert schema == {"type": "array", "items": {"type": "integer"}, "description": "ids"} + + +def test_build_optional_variadic_tuple(): + schema = KernelJsonSchemaBuilder.build(Optional[tuple[str, ...]]) + assert schema == {"type": ["array", "null"], "items": {"type": "string"}} + + def test_build_union(): schema = KernelJsonSchemaBuilder.build(Union[int, str]) assert schema == {"anyOf": [{"type": "integer"}, {"type": "string"}]}