openai/openai-python · error · TypeError

Unable to automatically parse response format type {text_for

Error message

Unable to automatically parse response format type {text_format}

What it means

parse_text only supports pydantic BaseModel and dataclass-like types as text_format. Passing any other type (int, str, dict, arbitrary class) raises TypeError('Unable to automatically parse response format type ...').

Source

Thrown at src/openai/lib/_parsing/_responses.py:157

            "output": output_list,
        },
    )


def parse_text(text: str, text_format: type[TextFormatT] | Omit) -> TextFormatT | None:
    if not is_given(text_format):
        return None

    if is_basemodel_type(text_format):
        return cast(TextFormatT, model_parse_json(text_format, text))

    if is_dataclass_like_type(text_format):
        if PYDANTIC_V1:
            raise TypeError(f"Non BaseModel types are only supported with Pydantic v2 - {text_format}")

        return pydantic.TypeAdapter(text_format).validate_json(text)

    raise TypeError(f"Unable to automatically parse response format type {text_format}")


def get_input_tool_by_name(*, input_tools: Iterable[ToolParam], name: str) -> FunctionToolParam | None:
    for tool in input_tools:
        if tool["type"] == "function" and tool.get("name") == name:
            return tool

    return None


def parse_function_tool_arguments(
    *,
    input_tools: Iterable[ToolParam] | Omit | None,
    function_call: ParsedResponseFunctionToolCall | ResponseFunctionToolCall,
) -> object:
    if input_tools is None or not is_given(input_tools):
        return None

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Wrap the desired shape in a pydantic BaseModel (e.g. class Output(BaseModel): value: str)
  2. Use responses.create with a raw text.format param and parse the output yourself

Example fix

# before
client.responses.parse(..., text_format=str)
# after
class Output(BaseModel):
    value: str
resp = client.responses.parse(..., text_format=Output)
text = resp.output_text  # or resp.output_parsed.value
Defensive patterns

Strategy: type-guard

Type guard

def is_parseable_text_format(t: type) -> bool:
    return is_basemodel_type(t) or is_dataclass_like_type(t)

Prevention

When it happens

Trigger: client.responses.parse(text_format=str) or text_format=some_plain_class.

Common situations: Expecting .parse() to return primitives; passing a schema dict instead of a Python type.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/7e2e3cf247b75ada. Report an issue: GitHub.