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 response_format is a dict whose 'type' value is neither 'json_object' nor 'json_schema'. The Responses Agent only supports those two structured formats via the dict path; any other type string (e.g. 'text', 'auto', 'json') is rejected.

Source

Thrown at python/semantic_kernel/agents/open_ai/openai_responses_agent.py:782

        if response_format is None or response_format == "auto":
            return None

        # TODO(evmattso): improve typing in this method
        if isinstance(response_format, dict):
            resp_type = response_format.get("type", None)

            if resp_type == "json_object":
                return {"type": "json_object"}
            if 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
                return response_format  # type: ignore

            raise AgentInitializationException(
                f"Encountered unexpected response_format type: {resp_type}. Allowed types are `json_object` "
                " and `json_schema`."
            )
        if isinstance(response_format, type):
            if issubclass(response_format, BaseModel):
                interim_format = type_to_text_format_param(response_format)
                if interim_format["type"] != "json_schema":
                    raise AgentInitializationException("Only 'json_schema' is allowed from that helper.")
                configured_format = {
                    "type": "json_schema",
                    "name": interim_format.get("name", response_format.__name__),
                    "schema": interim_format.get("schema"),
                    "strict": interim_format.get("strict", True),
                }
            else:
                # Build a schema from a plain Python class
                generated_schema = KernelJsonSchemaBuilder.build(parameter_type=response_format, structured_output=True)
                if generated_schema is None:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Use {'type': 'json_object'} or {'type': 'json_schema', ...} for structured output.
  2. For plain text, pass None or 'auto' (handled at the top of the method) rather than {'type': 'text'}.
  3. If you need a text format config, use the ResponseTextConfigParam path instead of a dict.

Example fix

// before
cfg = OpenAIResponsesAgent.configure_response_format({"type": "text"})

// after
cfg = OpenAIResponsesAgent.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 or response_format.get('type') is None, 'unsupported type'

Type guard

def is_supported_dict_type(fmt: dict) -> bool:
    return fmt.get('type') in ('json_object', 'json_schema')

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException
try:
    cfg = OpenAIResponsesAgent.configure_response_format(fmt)
except AgentInitializationException as e:
    if 'unexpected response_format type' in str(e):
        fmt['type'] = 'json_object'
        cfg = OpenAIResponsesAgent.configure_response_format(fmt)
    raise

Prevention

When it happens

Trigger: Passing response_format={'type': 'text'}, {'type': 'json'}, or any dict whose type field is an unrecognized string. The resp_type variable holds whatever was under the 'type' key.

Common situations: Porting a Chat Completions response_format that used 'text' or 'json_object' variants not supported by the Responses API, or setting type to a value from a different SDK version. The message echoes the offending resp_type.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/20d9b0e5b38690d3. Report an issue: GitHub.