diff --git a/src/anthropic/_models.py b/src/anthropic/_models.py index dc00516bc..b9b80256d 100644 --- a/src/anthropic/_models.py +++ b/src/anthropic/_models.py @@ -647,7 +647,7 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any] if not is_mapping(value): return value - _, items_type = get_args(type_) # Dict[_, items_type] + items_type = args[1] if len(args) >= 2 else object # Dict[_, items_type] return {key: construct_type(value=item, type_=items_type) for key, item in value.items()} if ( @@ -668,7 +668,7 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any] if not is_list(value): return value - inner_type = args[0] # List[inner_type] + inner_type = args[0] if args else object # List[inner_type] return [construct_type(value=entry, type_=inner_type) for entry in value] if origin == float: diff --git a/src/anthropic/_utils/_transform.py b/src/anthropic/_utils/_transform.py index 1e7e5ac80..75b09393f 100644 --- a/src/anthropic/_utils/_transform.py +++ b/src/anthropic/_utils/_transform.py @@ -180,7 +180,8 @@ def _transform_recursive( return _transform_typeddict(data, stripped_type) if origin == dict and is_mapping(data): - items_type = get_args(stripped_type)[1] + args = get_args(stripped_type) + items_type = args[1] if len(args) >= 2 else object return {key: _transform_recursive(value, annotation=items_type) for key, value in data.items()} if ( @@ -346,8 +347,9 @@ async def _async_transform_recursive( return await _async_transform_typeddict(data, stripped_type) if origin == dict and is_mapping(data): - items_type = get_args(stripped_type)[1] - return {key: _transform_recursive(value, annotation=items_type) for key, value in data.items()} + args = get_args(stripped_type) + items_type = args[1] if len(args) >= 2 else object + return {key: await _async_transform_recursive(value, annotation=items_type) for key, value in data.items()} if ( # List[T]