{
  "id": "python/pydantic-arbitrary-types-schema-generation",
  "signature": "pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'decimal.Decimal'>. 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 'decimal.Decimal'> 生成 pydantic-core schema。请在 model_config 中设置 arbitrary_types_allowed=True 或实现 __get_pydantic_core_schema__。",
  "regex": "pydantic\\.errors\\.PydanticSchemaGenerationError:\\ Unable\\ to\\ generate\\ pydantic\\-core\\ schema\\ for\\ <class\\ 'decimal\\.Decimal'>\\.\\ 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": "The field type is a custom class (or a third-party type) that Pydantic v2 does not know how to validate, and no core schema has been registered.",
  "root_cause_type": "generic",
  "root_cause_zh": "字段类型是 Pydantic v2 无法识别的自定义类或第三方类型，且未注册对应的 core schema。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Pydantic v2 uses model_config = ConfigDict(...); the inner Config class is deprecated and ignored in strict v2 builds.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disables validation entirely, so invalid instances pass silently and errors surface later in business logic.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "NewType is a static-typing alias; at runtime it is just the underlying type and does not register a schema.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from pydantic import BaseModel, ConfigDict\nclass Foo(BaseModel):\n    model_config = ConfigDict(arbitrary_types_allowed=True)\n    value: MyCustomClass",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from pydantic import GetCoreSchemaHandler\nfrom pydantic_core import core_schema\nclass MyCustomClass:\n    @classmethod\n    def __get_pydantic_core_schema__(cls, source, handler):\n        return core_schema.no_info_plain_validator_function(cls.validate)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "from typing import Annotated\nfrom pydantic import BeforeValidator\nMyType = Annotated[decimal.Decimal, BeforeValidator(lambda v: decimal.Decimal(str(v)))]",
      "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-02-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}