{
  "id": "python/pydantic-arbitrary-types-schema",
  "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": "A field uses a type (custom class, Decimal subclass, numpy dtype) that has no built-in pydantic-core schema.",
  "root_cause_type": "generic",
  "root_cause_zh": "字段使用了没有内置 pydantic-core schema 的类型（自定义类、Decimal 子类、numpy dtype 等）。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Disables validation and serialization; JSON schema loses type info.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses type guarantees; callers must re-parse everywhere.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Breaks all other models and is not supported across pydantic minor versions.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.88,
      "how": "from pydantic import BaseModel, ConfigDict\nclass M(BaseModel):\n    model_config = ConfigDict(arbitrary_types_allowed=True)\n    amount: Decimal",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.82,
      "how": "from typing import Annotated\nfrom pydantic import BaseModel, PlainSerializer\nfrom decimal import Decimal\nAmt = Annotated[Decimal, PlainSerializer(lambda d: str(d), return_type=str)]\nclass M(BaseModel):\n    amount: Amt",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-09",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}