{"record":{"id":"c0cc88dbb0672cad","repo":"openai/openai-python","slug":"unsupported-response-format-type-response-forma","errorCode":null,"errorMessage":"Unsupported response_format type - {response_format}","messagePattern":"Unsupported response_format type - (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/_parsing/_completions.py","lineNumber":279,"sourceCode":"\n    if is_response_format_param(response_format):\n        return response_format\n\n    # type checkers don't narrow the negation of a `TypeGuard` as it isn't\n    # a safe default behaviour but we know that at this point the `response_format`\n    # can only be a `type`\n    response_format = cast(type, response_format)\n\n    json_schema_type: type[pydantic.BaseModel] | pydantic.TypeAdapter[Any] | None = None\n\n    if is_basemodel_type(response_format):\n        name = response_format.__name__\n        json_schema_type = response_format\n    elif is_dataclass_like_type(response_format):\n        name = response_format.__name__\n        json_schema_type = pydantic.TypeAdapter(response_format)\n    else:\n        raise TypeError(f\"Unsupported response_format type - {response_format}\")\n\n    return {\n        \"type\": \"json_schema\",\n        \"json_schema\": {\n            \"schema\": to_strict_json_schema(json_schema_type),\n            \"name\": name,\n            \"strict\": True,\n        },\n    }\n","sourceCodeStart":261,"sourceCodeEnd":289,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/_parsing/_completions.py#L261-L289","documentation":"type_to_response_format_param converts a Python type into a json_schema response_format param for the API. It only supports pydantic BaseModel subclasses and dataclass-like types; anything else (built-ins, arbitrary classes, enums at top level) is unsupported.","triggerScenarios":"Passing a plain class, dict type, or primitive annotation where a response format type is expected in .parse() flows that build the API request schema.","commonSituations":"Passing an instance instead of the class; using non-Pydantic ORMs or attrs classes as output models.","solutions":["Define the output as a pydantic BaseModel or dataclass","If you already have a JSON schema, pass response_format={'type':'json_schema','json_schema':{...}} directly instead of a Python type"],"exampleFix":"# before\nclass Output: ...  # plain class\n# after\nfrom pydantic import BaseModel\nclass Output(BaseModel): ...","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def usable_format(t: object) -> bool:\n    return inspect.isclass(t) and (issubclass(t, pydantic.BaseModel) or dataclasses.is_dataclass(t))","tryCatchPattern":null,"preventionTips":["Pass response_format as a class, never an instance","Use raw json_schema response_format dicts when you already have a schema"],"tags":["parsing","json-schema","type-validation"],"backgroundTag":"unsupported-response-format","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}