{"record":{"id":"5b8b7afea6794192","repo":"microsoft/semantic-kernel","slug":"encountered-unexpected-response-format-type-resp","errorCode":null,"errorMessage":"Encountered unexpected response_format type: {resp_type}. Allowed types are `json_object`  and `json_schema`.","messagePattern":"Encountered unexpected response_format type: (.+?)\\. Allowed types are `json_object`  and `json_schema`\\.","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_assistant_agent.py","lineNumber":675,"sourceCode":"        \"\"\"\n        if response_format is None or response_format == \"auto\":\n            return None\n\n        configured_response_format = None\n        if isinstance(response_format, dict):\n            resp_type = response_format.get(\"type\")\n            if resp_type == \"json_object\":\n                configured_response_format = {\"type\": \"json_object\"}\n            elif resp_type == \"json_schema\":\n                json_schema = response_format.get(\"json_schema\")  # type: ignore\n                if not isinstance(json_schema, dict):\n                    raise AgentInitializationException(\n                        \"If response_format has type 'json_schema', 'json_schema' must be a valid dictionary.\"\n                    )\n                # We're assuming the response_format has already been provided in the correct format\n                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            )","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_assistant_agent.py#L657-L693","documentation":"Raised by configure_response_format() when the response_format dict has a 'type' value that is neither 'json_object' nor 'json_schema'. The dict branch only recognizes those two; any other type string (e.g. 'text', 'json', a typo) is rejected because the library cannot map it to a valid assistant response_format option.","triggerScenarios":"Passing response_format={'type':'text'} or {'type':'json'}; a stray/typo type value; using an OpenAI Responses-API type name against the Assistant API which supports a smaller set.","commonSituations":"Mixing Assistant API and Responses API response_format vocabularies; typo in the type field; reading a type from user input without validating the allowed set.","solutions":["Use only 'json_object' or 'json_schema' for the dict-form response_format.","Pass response_format=None or 'auto' for plain text output.","Sanitize user-supplied type values against {'json_object','json_schema'} before calling."],"exampleFix":"# before\nfmt = OpenAIAssistantAgent.configure_response_format({'type':'json'})\n\n# after\nfmt = OpenAIAssistantAgent.configure_response_format({'type':'json_object'})","handlingStrategy":"validation","validationCode":"ALLOWED = {'json_object', 'json_schema'}\nif isinstance(response_format, dict):\n    assert response_format.get('type') in ALLOWED, f\"type must be one of {ALLOWED}\"","typeGuard":"def is_allowed_response_format_type(rf) -> bool:\n    return not isinstance(rf, dict) or rf.get('type') in {None, 'json_object', 'json_schema'}","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\ntry:\n    fmt = OpenAIAssistantAgent.configure_response_format(response_format)\nexcept AgentInitializationException as e:\n    if 'unexpected response_format type' in str(e):\n        fmt = OpenAIAssistantAgent.configure_response_format({'type':'json_object'})","preventionTips":["Restrict type to json_object/json_schema.","Use None/'auto' for text.","Sanitize user-supplied type values."],"tags":["configuration","agents","openai-assistant","response-format"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}