microsoft/semantic-kernel · error · AgentInitializationException
Encountered unexpected response_format type: {resp_type}. Al
Error message
Encountered unexpected response_format type: {resp_type}. Allowed types are `json_object` and `json_schema`. What it means
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.
Source
Thrown at python/semantic_kernel/agents/open_ai/openai_assistant_agent.py:675
"""
if response_format is None or response_format == "auto":
return None
configured_response_format = None
if isinstance(response_format, dict):
resp_type = response_format.get("type")
if resp_type == "json_object":
configured_response_format = {"type": "json_object"}
elif resp_type == "json_schema":
json_schema = response_format.get("json_schema") # type: ignore
if not isinstance(json_schema, dict):
raise AgentInitializationException(
"If response_format has type 'json_schema', 'json_schema' must be a valid dictionary."
)
# We're assuming the response_format has already been provided in the correct format
configured_response_format = response_format # type: ignore
else:
raise AgentInitializationException(
f"Encountered unexpected response_format type: {resp_type}. Allowed types are `json_object` "
" and `json_schema`."
)
elif isinstance(response_format, type):
# If it's a type, differentiate based on whether it's a BaseModel subclass
if issubclass(response_format, BaseModel):
configured_response_format = type_to_response_format_param(response_format) # type: ignore
else:
generated_schema = KernelJsonSchemaBuilder.build(parameter_type=response_format, structured_output=True)
assert generated_schema is not None # nosec
configured_response_format = generate_structured_output_response_format_schema(
name=response_format.__name__, schema=generated_schema
)
else:
# If it's not a dict or a type, throw an exception
raise AgentInitializationException(
"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None"
)View on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
fmt = OpenAIAssistantAgent.configure_response_format({'type':'json'})
# after
fmt = OpenAIAssistantAgent.configure_response_format({'type':'json_object'}) Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = {'json_object', 'json_schema'}
if isinstance(response_format, dict):
assert response_format.get('type') in ALLOWED, f"type must be one of {ALLOWED}" Type guard
def is_allowed_response_format_type(rf) -> bool:
return not isinstance(rf, dict) or rf.get('type') in {None, 'json_object', 'json_schema'} Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException
try:
fmt = OpenAIAssistantAgent.configure_response_format(response_format)
except AgentInitializationException as e:
if 'unexpected response_format type' in str(e):
fmt = OpenAIAssistantAgent.configure_response_format({'type':'json_object'}) Prevention
- Restrict type to json_object/json_schema.
- Use None/'auto' for text.
- Sanitize user-supplied type values.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- If response_format has type 'json_schema', 'json_schema' mus
- response_format must be a dictionary, a subclass of BaseMode
- Failed to create OpenAI settings.
- The OpenAI API key is required.
- The OpenAI model ID is required.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/5b8b7afea6794192.
Report an issue: GitHub.