{"record":{"id":"6c7ad5d80682a6d4","repo":"microsoft/autogen","slug":"cls-name-is-a-namespace-class-and-cannot-be","errorCode":null,"errorMessage":"{cls.__name__} is a namespace class and cannot be instantiated.","messagePattern":"(.+?) is a namespace class and cannot be instantiated\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/models/_model_client.py","lineNumber":98,"sourceCode":"        \"claude-4-opus\",\n        \"claude-4-sonnet\",\n        # llama_models\n        \"llama-3.3-8b\",\n        \"llama-3.3-70b\",\n        \"llama-4-scout\",\n        \"llama-4-maverick\",\n        # mistral_models\n        \"codestral\",\n        \"open-codestral-mamba\",\n        \"mistral\",\n        \"ministral\",\n        \"pixtral\",\n        # unknown\n        \"unknown\",\n    ]\n\n    def __new__(cls, *args: Any, **kwargs: Any) -> ModelFamily:\n        raise TypeError(f\"{cls.__name__} is a namespace class and cannot be instantiated.\")\n\n    @staticmethod\n    def is_claude(family: str) -> bool:\n        return family in (\n            ModelFamily.CLAUDE_3_HAIKU,\n            ModelFamily.CLAUDE_3_SONNET,\n            ModelFamily.CLAUDE_3_OPUS,\n            ModelFamily.CLAUDE_3_5_HAIKU,\n            ModelFamily.CLAUDE_3_5_SONNET,\n            ModelFamily.CLAUDE_3_7_SONNET,\n            ModelFamily.CLAUDE_4_OPUS,\n            ModelFamily.CLAUDE_4_SONNET,\n        )\n\n    @staticmethod\n    def is_gemini(family: str) -> bool:\n        return family in (\n            ModelFamily.GEMINI_1_5_FLASH,","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/models/_model_client.py#L80-L116","documentation":"ModelFamily is a namespace class (a typed container of string constants like ModelFamily.GPT_4O, CLAUDE_3_5_SONNET) with helper static methods such as is_claude/is_openai. Its __new__ unconditionally raises TypeError to prevent instantiation or accidental subclass-with-instance use. You are meant to reference its attributes and static methods only.","triggerScenarios":"`ModelFamily()` or `ModelFamily(\"gpt-4o\")` — e.g. trying to construct a family object from a config string; subclassing ModelFamily and instantiating the subclass (TypeError is inherited via __new__); frameworks that reflectively instantiate annotated classes when deserializing a config containing ModelFamily.","commonSituations":"Deserializing model configs where a field is typed ModelFamily and the loader instantiates the class instead of resolving a constant; copy-paste from code that uses model=\"gpt-4o\" strings; assuming ModelFamily is an Enum whose members are constructed.","solutions":["Use the string constants: pass `family=ModelFamily.GPT_4O` (or the plain string \"gpt-4o\") in ModelInfo.","When deserializing, map strings to constants: `getattr(ModelFamily, name.upper())` or keep plain strings.","Remove any `ModelFamily(...)` constructor calls; call static helpers as `ModelFamily.is_claude(family)`."],"exampleFix":"# before\nfamily = ModelFamily(\"gpt-4o\")  # TypeError: namespace class\n\n# after\nfamily = ModelFamily.GPT_4O  # or the plain string \"gpt-4o\"","handlingStrategy":"type-guard","validationCode":"def resolve_family(name: str) -> str:\n    return getattr(ModelFamily, name.upper(), ModelFamily.UNKNOWN)","typeGuard":"from autogen_core.models import ModelFamily\n\ndef is_model_family_value(v: object) -> bool:\n    return isinstance(v, str) and v in ModelFamily.__dict__.values().__iter__().__class__ and v in {\n        val for k, val in vars(ModelFamily).items() if not k.startswith(\"_\") and isinstance(val, str)\n    }","tryCatchPattern":null,"preventionTips":["ModelFamily is a namespace of str constants: reference attributes, never construct it.","Keep ModelInfo['family'] as a plain string in configs and map to constants only in code.","Exclude ModelFamily-typed fields from reflective deserialization."],"tags":["python","autogen-core","models","api-misuse","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}