{"record":{"id":"641314d485a4b5b9","repo":"microsoft/semantic-kernel","slug":"response-format-must-be-a-dictionary-a-subclass-o","errorCode":null,"errorMessage":"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None","messagePattern":"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_assistant_agent.py","lineNumber":691,"sourceCode":"                configured_response_format = response_format  # type: ignore\n            else:\n                raise AgentInitializationException(\n                    f\"Encountered unexpected response_format type: {resp_type}. Allowed types are `json_object` \"\n                    \" and `json_schema`.\"\n                )\n        elif isinstance(response_format, type):\n            # If it's a type, differentiate based on whether it's a BaseModel subclass\n            if issubclass(response_format, BaseModel):\n                configured_response_format = type_to_response_format_param(response_format)  # type: ignore\n            else:\n                generated_schema = KernelJsonSchemaBuilder.build(parameter_type=response_format, structured_output=True)\n                assert generated_schema is not None  # nosec\n                configured_response_format = generate_structured_output_response_format_schema(\n                    name=response_format.__name__, schema=generated_schema\n                )\n        else:\n            # If it's not a dict or a type, throw an exception\n            raise AgentInitializationException(\n                \"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None\"\n            )\n\n        return configured_response_format  # type: ignore\n\n    # endregion\n\n    # region Agent Channel Methods\n\n    def get_channel_keys(self) -> Iterable[str]:\n        \"\"\"Get the channel keys.\n\n        Returns:\n            Iterable[str]: The channel keys.\n        \"\"\"\n        # Distinguish from other channel types.\n        yield f\"{OpenAIAssistantAgent.__name__}\"\n","sourceCodeStart":673,"sourceCodeEnd":709,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_assistant_agent.py#L673-L709","documentation":"Raised by configure_response_format() when response_format is not None/'auto', not a dict, and not a Python type/class. The method supports dict, BaseModel subclass, a plain class (schema built via KernelJsonSchemaBuilder), or None; anything else (a string, an int, a list, an instance object) hits the final else branch.","triggerScenarios":"Passing response_format='json_object' (string instead of dict), an instance of a model rather than the class, a list, or any other non-supported value.","commonSituations":"Passing a string shorthand ('auto' is special-cased but other strings are not); passing a model instance instead of the model class; integrating with code that sends arbitrary JSON values.","solutions":["Pass None or 'auto' for default text, a dict for json_object/json_schema, or a BaseModel subclass / plain class for schema generation.","If you meant JSON mode, pass {'type':'json_object'} not the bare string.","Type-check response_format before the call: must be None, dict, or type."],"exampleFix":"# before\nfmt = OpenAIAssistantAgent.configure_response_format('json_object')\n\n# after\nfmt = OpenAIAssistantAgent.configure_response_format({'type':'json_object'})","handlingStrategy":"type-guard","validationCode":"from typing import is_type\nok = response_format is None or isinstance(response_format, dict) or is_type(response_format)\nassert ok, 'response_format must be None, dict, or a class'","typeGuard":"import inspect\ndef is_supported_response_format(rf) -> bool:\n    if rf is None or isinstance(rf, dict):\n        return True\n    return inspect.isclass(rf)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\ntry:\n    fmt = OpenAIAssistantAgent.configure_response_format(response_format)\nexcept AgentInitializationException as e:\n    if 'must be a dictionary' in str(e):\n        fmt = None  # default to text","preventionTips":["Pass None/dict/class only.","Wrap bare strings in {'type': ...}.","Pass the class, not an instance."],"tags":["configuration","agents","openai-assistant","response-format","type-mismatch"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}