{"record":{"id":"11ec3ef1a26a787b","repo":"openai/openai-python","slug":"non-basemodel-types-are-only-supported-with-pydant-11ec3e","errorCode":null,"errorMessage":"Non BaseModel types are only supported with Pydantic v2 - {model}","messagePattern":"Non BaseModel types are only supported with Pydantic v2 - (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/_pydantic.py","lineNumber":22,"sourceCode":"from typing import Any, TypeVar\nfrom typing_extensions import TypeGuard\n\nimport pydantic\n\nfrom .._types import NOT_GIVEN\nfrom .._utils import is_dict as _is_dict, is_list\nfrom .._compat import PYDANTIC_V1, model_json_schema\n\n_T = TypeVar(\"_T\")\n\n\ndef to_strict_json_schema(model: type[pydantic.BaseModel] | pydantic.TypeAdapter[Any]) -> dict[str, Any]:\n    if inspect.isclass(model) and is_basemodel_type(model):\n        schema = model_json_schema(model)\n    elif (not PYDANTIC_V1) and isinstance(model, pydantic.TypeAdapter):\n        schema = model.json_schema()\n    else:\n        raise TypeError(f\"Non BaseModel types are only supported with Pydantic v2 - {model}\")\n\n    return _ensure_strict_json_schema(schema, path=(), root=schema)\n\n\ndef _ensure_strict_json_schema(\n    json_schema: object,\n    *,\n    path: tuple[str, ...],\n    root: dict[str, object],\n) -> dict[str, Any]:\n    \"\"\"Mutates the given JSON schema to ensure it conforms to the `strict` standard\n    that the API expects.\n    \"\"\"\n    if not is_dict(json_schema):\n        raise TypeError(f\"Expected {json_schema} to be a dictionary; path={path}\")\n\n    defs = json_schema.get(\"$defs\")\n    if is_dict(defs):","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/_pydantic.py#L4-L40","documentation":"to_strict_json_schema converts a type into the strict JSON schema the API needs for structured outputs. It accepts only pydantic BaseModel classes or pydantic v2 TypeAdapter instances; anything else (plain classes, pydantic v1 types, instances) raises this TypeError. Note dataclass-like types must already be wrapped in a TypeAdapter by callers such as type_to_response_format_param.","triggerScenarios":"Calling to_strict_json_schema(SomePlainClass), passing a BaseModel instance instead of the class, or passing a TypeAdapter under pydantic v1 (where the isinstance check is short-circuited by 'not PYDANTIC_V1').","commonSituations":"Direct use of the helper with unsupported types; pydantic v1 environments; passing a class that inherits from something BaseModel-like but is not a real BaseModel.","solutions":["Pass the pydantic BaseModel class itself (not an instance)","For dataclass/TypedDict types, wrap with pydantic.TypeAdapter (requires pydantic v2)","Use the SDK helpers pydantic_function_tool / type_to_response_format_param which do the wrapping for you"],"exampleFix":"# before\nschema = to_strict_json_schema(MyDataclass)\n# after\nschema = to_strict_json_schema(pydantic.TypeAdapter(MyDataclass))","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def strict_schema_input_ok(obj: object) -> bool:\n    if inspect.isclass(obj):\n        return is_basemodel_type(obj)\n    return (not PYDANTIC_V1) and isinstance(obj, pydantic.TypeAdapter)","tryCatchPattern":null,"preventionTips":["Prefer SDK helpers (pydantic_function_tool) over calling to_strict_json_schema directly","Pass classes, not instances"],"tags":["json-schema","pydantic","strict-mode"],"backgroundTag":"unsupported-schema-input","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}