# fastapi.exceptions.RequestValidationError: path -> id：值不是有效的 uuid (type=type_error.uuid)

- **ID:** `python/fastapi-path-param-422-uuid`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

路径参数声明为 UUID，但 URL 片段不是有效的 UUID 字符串。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   @app.get('/items/{item_id}')
def get(item_id: str):
    try: uid = UUID(item_id)
    except ValueError: raise HTTPException(400)
   ```
2. **** (88% 成功率)
   ```
   from fastapi import Path
def get(item_id: UUID = Path(...)): ...
   ```

## 无效尝试

- **** — Still fails if the regex matches but the value is not a UUID. (75% 失败率)
- **** — Validation runs before the handler; except never triggers. (90% 失败率)
