Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 19:30 UTC
Fix type casting of union/pydantic types
haxzie committed
Sep 30, 2025 at 12:01 UTC
b1f130c220870e590e6d0f7713c1ad170a1ca48e
1 file changed
+5
-4
python/composio/utils/shared.py
+5
-4
@@ -4,6 +4,7 @@ Shared utils.
4
5
import typing as t
6
import uuid
7
+from functools import reduce
8
from inspect import Parameter
9
10
from pydantic import BaseModel, Field, create_model
@@ -59,10 +60,10 @@ def json_schema_to_pydantic_type(
60
if len(pydantic_types) == 1:
61
return pydantic_types[0]
62
# Create Union with any number of types
62
- # Cast all types and create tuple
63
- cast_types = tuple(t.cast(t.Type, ptype) for ptype in pydantic_types)
64
- # typing.Union[tuple] works in Python 3.8+ and maintains __origin__ attribute
65
- return t.Union[cast_types]
63
+ # Cast all types and use functools.reduce to create proper Union
64
+ cast_types = [t.cast(t.Type, ptype) for ptype in pydantic_types]
65
+ # Use reduce to create Union[Type1, Type2, ...] properly
66
+ return reduce(lambda a, b: t.Union[a, b], cast_types)
67
68
# Add fallback type - string
69
if "type" not in json_schema: