{"id":"76560f80a77d5538","repo":"pydantic/pydantic","slug":"unexpected-type-of-exclude-value-class-name","errorCode":null,"errorMessage":"Unexpected type of exclude value {class_name}","messagePattern":"Unexpected type of exclude value (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pydantic/_internal/_utils.py","lineNumber":288,"sourceCode":"            merge_keys = list(base) + [k for k in override if k not in base]\n\n        merged: dict[int | str, Any] = {}\n        for k in merge_keys:\n            merged_item = cls.merge(base.get(k), override.get(k), intersect=intersect)\n            if merged_item is not None:\n                merged[k] = merged_item\n\n        return merged\n\n    @staticmethod\n    def _coerce_items(items: AbstractSetIntStr | MappingIntStrAny) -> MappingIntStrAny:\n        if isinstance(items, Mapping):\n            pass\n        elif isinstance(items, AbstractSet):\n            items = dict.fromkeys(items, ...)  # type: ignore\n        else:\n            class_name = getattr(items, '__class__', '???')\n            raise TypeError(f'Unexpected type of exclude value {class_name}')\n        return items  # type: ignore\n\n    @classmethod\n    def _coerce_value(cls, value: Any) -> Any:\n        if value is None or cls.is_true(value):\n            return value\n        return cls._coerce_items(value)\n\n    @staticmethod\n    def is_true(v: Any) -> bool:\n        return v is True or v is ...\n\n    def __repr_args__(self) -> _repr.ReprArgs:\n        return [(None, self._items)]\n\n\nif TYPE_CHECKING:\n","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/pydantic/pydantic/blob/2e5f0e2b4218de31709f1cf9c5bc61ea97a68835/pydantic/_internal/_utils.py#L270-L306","documentation":"A `TypeError` from `ValueItems._coerce_items`, raised when the top-level `include`/`exclude` argument is neither a Mapping (dict) nor an AbstractSet (set). Pydantic only accepts these two shapes for include/exclude specifications.","triggerScenarios":"Passing `exclude=[0, 1]` (a list) or `exclude=('a', 'b')` (a tuple) or a custom iterable to `model_dump`/`model_dump_json`. Lists/tuples/strings are not accepted; only sets and dicts are.","commonSituations":"Passing JSON-decoded lists (from a web request) directly as exclude; assuming any iterable works; converting between set/list representations carelessly.","solutions":["Convert the value to a set: `model_dump(exclude=set(my_list))`.","If you need nested exclusions, pass a dict: `exclude={'a', 'b': {'c'}}`.","Validate that the include/exclude arg is a set or dict before serializing."],"exampleFix":"# before\nm.model_dump(exclude=['secret', 'token'])  # list rejected\n\n# after\nm.model_dump(exclude={'secret', 'token'})  # set accepted","handlingStrategy":"validation","validationCode":"from collections.abc import Mapping, Set\ndef valid_include_exclude(v) -> bool:\n    return v is None or isinstance(v, (Mapping, Set))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass sets or dicts for include/exclude, never lists/tuples.","Sanitize user-provided exclude input (convert lists to sets).","Type your serialization helpers to accept only Set|Mapping."],"tags":["pydantic","serialization","exclude","valueitems","argument-validation"],"analyzedSha":"2e5f0e2b4218de31709f1cf9c5bc61ea97a68835","analyzedAt":"2026-08-04T19:54:21.281Z","schemaVersion":2}