{"record":{"id":"63bcb686d3f4d1ec","repo":"microsoft/semantic-kernel","slug":"response-format-must-be-a-dictionary-a-subclass-o-63bcb6","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_responses_agent.py","lineNumber":809,"sourceCode":"                configured_format = {\n                    \"type\": \"json_schema\",\n                    \"name\": interim_format.get(\"name\", response_format.__name__),\n                    \"schema\": interim_format.get(\"schema\"),\n                    \"strict\": interim_format.get(\"strict\", True),\n                }\n            else:\n                # Build a schema from a plain Python class\n                generated_schema = KernelJsonSchemaBuilder.build(parameter_type=response_format, structured_output=True)\n                if generated_schema is None:\n                    raise AgentInitializationException(f\"Could not generate schema for the type {response_format}.\")\n                configured_format = {\n                    \"type\": \"json_schema\",\n                    \"name\": response_format.__name__,\n                    \"schema\": generated_schema,\n                    \"strict\": True,\n                }\n        else:\n            raise AgentInitializationException(\n                \"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None\"\n            )\n\n        return {\"format\": configured_format}\n\n    # endregion\n\n    # region Invocation Methods\n\n    @trace_agent_get_response\n    @override\n    async def get_response(\n        self,\n        messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,\n        *,\n        thread: AgentThread | None = None,\n        arguments: KernelArguments | None = None,\n        kernel: \"Kernel | None\" = None,","sourceCodeStart":791,"sourceCodeEnd":827,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_responses_agent.py#L791-L827","documentation":"Raised by configure_response_format() when response_format is none of the accepted kinds: it is not None/'auto', not a dict, not a type/class. This is the final else branch — the value's top-level type is entirely unrecognized.","triggerScenarios":"Passing a response_format that is an instance/object (not a class), an int, a list, a tuple, or any other non-dict, non-type value. (Strings are partly handled: 'auto' returns None earlier, but other bare strings fall through to this branch.)","commonSituations":"Passing an already-instantiated object instead of the class, passing a JSON string (instead of a dict), or passing a random primitive. Also when a variable intended to hold a format is accidentally left as some other value.","solutions":["Pass None, a dict (with type 'json_object'/'json_schema'), a pydantic BaseModel subclass, or a plain Python class.","If you have a JSON string, json.loads() it into a dict first.","Pass the class itself (e.g. MyModel), not an instance (e.g. MyModel())."],"exampleFix":"// before\ncfg = OpenAIResponsesAgent.configure_response_format(MyModel())\n\n// after\ncfg = OpenAIResponsesAgent.configure_response_format(MyModel)","handlingStrategy":"type-guard","validationCode":"from pydantic import BaseModel\nvalid = response_format is None or isinstance(response_format, dict) or isinstance(response_format, type)\nassert valid, 'response_format must be None, a dict, a class, or a BaseModel subclass'","typeGuard":"from pydantic import BaseModel\ndef is_accepted_response_format(fmt) -> bool:\n    if fmt is None:\n        return True\n    if isinstance(fmt, dict):\n        return True\n    if isinstance(fmt, type):\n        return True\n    return False","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\ntry:\n    cfg = OpenAIResponsesAgent.configure_response_format(fmt)\nexcept AgentInitializationException as e:\n    if 'must be a dictionary' in str(e):\n        cfg = None  # or coerce fmt to a dict/class\n    raise","preventionTips":["Pass the class, not an instance, when using a model/type.","json.loads() any JSON string into a dict first.","Restrict response_format to None, dict, BaseModel subclass, or plain class."],"tags":["response-format","type-check","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}