Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions python/semantic_kernel/schema/kernel_json_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions python/tests/unit/schema/test_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]}
Expand Down
Loading