diff --git a/src/anthropic/_models.py b/src/anthropic/_models.py index dc00516b..2acf3a89 100644 --- a/src/anthropic/_models.py +++ b/src/anthropic/_models.py @@ -647,7 +647,8 @@ 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] + args = get_args(type_) + items_type = args[1] if args else object # Dict[_, items_type]; plain dict has no args return {key: construct_type(value=item, type_=items_type) for key, item in value.items()} if ( diff --git a/tests/test_models.py b/tests/test_models.py index 195f2307..513302b8 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1014,4 +1014,9 @@ class Model(BaseModel): # falls back to list of chars rather than calling str(["h", "e", "l", "l", "o"]) assert m.data["items"] == ["h", "e", "l", "l", "o"] - assert m.model_dump()["data"]["items"] == ["h", "e", "l", "l", "o"] + + +def test_construct_type_bare_dict() -> None: + # plain `dict` with no type parameters should not raise ValueError + result = construct_type(value={"key": "value"}, type_=dict) + assert result == {"key": "value"}