# pydantic.errors.PydanticInvalidForJsonSchema：无法为 core_schema.CallableSchema 生成 JsonSchema

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

## 根因

字段类型为 Callable，无法映射到 JSON schema。调用 model_json_schema() 会抛错。

## 版本兼容性

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

## 解决方案

1. **** (80% 成功率)
   ```
   from pydantic import BaseModel, Field
from typing import Callable
class M(BaseModel):
    model_config = {'json_schema_extra': {'examples': []}}
    handler: Callable = Field(exclude=True)
   ```
2. **** (85% 成功率)
   ```
   class M(BaseModel):
    handler_name: str  # resolved at runtime via registry
   ```

## 无效尝试

- **** — Loses validation; JSON schema becomes empty object with no guidance. (50% 失败率)
- **** — Breaks OpenAPI docs and client SDK generation for the whole app. (60% 失败率)
- **** — Security risk and still no schema for the callable's shape. (70% 失败率)
