{"record":{"id":"e0398aa3a706fe6b","repo":"microsoft/autogen","slug":"expected-dict-or-cls-name-instance-got-typ","errorCode":null,"errorMessage":"Expected dict or {cls.__name__} instance, got {type(value)}","messagePattern":"Expected dict or (.+?) instance, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_image.py","lineNumber":97,"sourceCode":"\n    # Returns openai.types.chat.ChatCompletionContentPartImageParam, which is a TypedDict\n    # We don't use the explicit type annotation so that we can avoid a dependency on the OpenAI Python SDK in this package.\n    def to_openai_format(self, detail: Literal[\"auto\", \"low\", \"high\"] = \"auto\") -> Dict[str, Any]:\n        return {\"type\": \"image_url\", \"image_url\": {\"url\": self.data_uri, \"detail\": detail}}\n\n    @classmethod\n    def __get_pydantic_core_schema__(cls, source_type: Any, handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:\n        # Custom validation\n        def validate(value: Any, validation_info: ValidationInfo) -> Image:\n            if isinstance(value, dict):\n                base_64 = cast(str | None, value.get(\"data\"))  # type: ignore\n                if base_64 is None:\n                    raise ValueError(\"Expected 'data' key in the dictionary\")\n                return cls.from_base64(base_64)\n            elif isinstance(value, cls):\n                return value\n            else:\n                raise TypeError(f\"Expected dict or {cls.__name__} instance, got {type(value)}\")\n\n        # Custom serialization\n        def serialize(value: Image) -> dict[str, Any]:\n            return {\"data\": value.to_base64()}\n\n        return core_schema.with_info_after_validator_function(\n            validate,\n            core_schema.any_schema(),  # Accept any type; adjust if needed\n            serialization=core_schema.plain_serializer_function_ser_schema(serialize),\n        )\n\n\ndef _convert_base64_to_data_uri(base64_image: str) -> str:\n    def _get_mime_type_from_data_uri(base64_image: str) -> str:\n        # Decode the base64 string\n        image_data = base64.b64decode(base64_image)\n        # Check the first few bytes for known signatures\n        if image_data.startswith(b\"\\xff\\xd8\\xff\"):","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_image.py#L79-L115","documentation":"Error \"Expected dict or {cls.__name__} instance, got {type(value)}\" thrown in microsoft/autogen.","triggerScenarios":"Thrown at python/packages/autogen-core/src/autogen_core/_image.py:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a dict or an instance of the expected class"],"exampleFix":"Construct the proper model instance instead of the raw value","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}