# fastapi.exceptions.FastAPIError: Invalid args for response field

- **ID:** `python/fastapi-dependency-injection-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI 依赖注入中的响应模型参数类型不匹配

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## Workarounds

1. **检查并修正依赖函数的返回类型** (90% success)
   ```
   def get_db() -> Session:
    return Session()
@app.get('/items', response_model=List[Item])
def get_items(db: Session = Depends(get_db)):
    ...
   ```
2. **使用正确的依赖注入语法** (95% success)
   ```
   from fastapi import Depends
@app.get('/')
def root(db: Session = Depends(get_db)):
    ...
   ```

## Dead Ends

- **删除响应模型参数但保留依赖** — 依赖注入仍然会解析，但响应格式可能错误 (60% fail)
- **将所有参数改为 Any 类型** — 失去了类型安全，可能隐藏错误 (70% fail)
