{
  "id": "python/pydantic-arbitrary-type-not-allowed",
  "signature": "pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'numpy.ndarray'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.",
  "signature_zh": "pydantic.errors.PydanticSchemaGenerationError: 无法为 <class 'numpy.ndarray'> 生成 pydantic-core 模式。请在 model_config 中设置 arbitrary_types_allowed=True 或实现 __get_pydantic_core_schema__。",
  "regex": "pydantic\\.errors\\.PydanticSchemaGenerationError:\\ Unable\\ to\\ generate\\ pydantic\\-core\\ schema\\ for\\ <class\\ 'numpy\\.ndarray'>\\.\\ Set\\ `arbitrary_types_allowed=True`\\ in\\ the\\ model_config\\ to\\ ignore\\ this\\ error\\ or\\ implement\\ `__get_pydantic_core_schema__`\\ on\\ your\\ type\\ to\\ fully\\ support\\ it\\.",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A field uses a third-party class that Pydantic does not know how to validate. Pydantic v2 requires either arbitrary_types_allowed or a custom core schema for unknown types.",
  "root_cause_type": "generic",
  "root_cause_zh": "字段使用了 Pydantic 无法验证的第三方类。Pydantic v2 对未知类型要求设置 arbitrary_types_allowed 或自定义核心模式。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Pydantic still cannot build a schema for it; the error reappears at class definition or import time.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disables all validation and serialization for that field, losing type safety and JSON output.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from pydantic import BaseModel, ConfigDict\nimport numpy as np\n\nclass Model(BaseModel):\n    model_config = ConfigDict(arbitrary_types_allowed=True)\n    arr: np.ndarray",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "from pydantic import field_serializer\n\nclass Model(BaseModel):\n    arr: np.ndarray\n\n    @field_serializer('arr')\n    def ser(self, v):\n        return v.tolist()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}