# pydantic.errors.PydanticInvalidForJsonSchema: 无法为核心模式 IsInstanceSchema (<class 'decimal.Decimal'>) 生成 JsonSchema

- **ID:** `python/pydantic-json-schema-generation-error`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

字段使用了没有定义 JSON Schema 表示的任意 Python 类型（通过 arbitrary_types_allowed 或自定义类），导致 model_json_schema() 失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   from typing import Annotated
from pydantic import BaseModel, WithJsonSchema

class Model(BaseModel):
    amount: Annotated[Decimal, WithJsonSchema({'type': 'string', 'format': 'decimal'})]
   ```
2. **** (88% 成功率)
   ```
   class Model(BaseModel):
    amount: float  # or str; convert to Decimal in business logic
   ```

## 无效尝试

- **** — Returns an empty schema, breaking OpenAPI docs and client generation downstream. (70% 失败率)
- **** — This allows the type at validation time but does not teach Pydantic how to serialize it to JSON Schema. (80% 失败率)
