Maintenance in progress: we are indexing a large batch of new skills. Some pages may load slowly or briefly show no results. Nothing is lost, and everything is back to normal within the hour.
Reviews FastAPI code for routing patterns, dependency injection, validation, and async handlers. Use when reviewing FastAPI apps, checking APIRouter setup, Depends() usage, or response models.
1---2name: fastapi-code-review3description: Reviews FastAPI code for routing patterns, dependency injection, validation, and async handlers. Use when reviewing FastAPI apps, checking APIRouter setup, Depends() usage, or response models.4---56# FastAPI Code Review78## Quick Reference910| Issue Type | Reference |11|------------|-----------|12| APIRouter setup, response_model, status codes | [references/routes.md](references/routes.md) |13| Depends(), yield deps, cleanup, shared deps | [references/dependencies.md](references/dependencies.md) |14| Pydantic models, HTTPException, 422 handling | [references/validation.md](references/validation.md) |15| Async handlers, blocking I/O, background tasks | [references/async.md](references/async.md) |1617## Review Checklist1819- [ ] APIRouter with proper prefix and tags20- [ ] All routes specify `response_model` for type safety21- [ ] Correct HTTP methods (GET, POST, PUT, DELETE, PATCH)22- [ ] Proper status codes (200, 201, 204, 404, etc.)23- [ ] Dependencies use `Depends()` not manual calls24- [ ] Yield dependencies have proper cleanup25- [ ] Request/Response models use Pydantic26- [ ] HTTPException with status code and detail27- [ ] All route handlers are `async def`28- [ ] No blocking I/O (`requests`, `time.sleep`, `open()`)29- [ ] Background tasks for non-blocking operations30- [ ] No bare `except` in route handlers3132## Valid Patterns (Do NOT Flag)3334These are idiomatic FastAPI patterns that may appear problematic but are correct:3536- **Pydantic validates request body automatically** - No manual validation needed when using typed Pydantic models as parameters37- **Dependency injection for database sessions** - Sessions come from `Depends()`, not passed as function arguments38- **HTTPException for all HTTP errors** - FastAPI handles conversion to proper HTTP responses39- **Async def endpoint without await** - May be using sync dependencies or simple operations; FastAPI handles this40- **Type annotation on Depends()** - This is documentation/IDE support, not a type assertion41- **Query/Path/Body defaults** - FastAPI processes these at runtime, not traditional Python defaults42- **Returning dict from endpoint** - Pydantic converts automatically if `response_model` is set4344## Context-Sensitive Rules4546Only flag issues when the context warrants it:4748- **Flag missing validation** ONLY IF the field isn't already in a Pydantic model with validators49- **Flag missing auth** ONLY IF the endpoint isn't using `Depends()` with an auth dependency50- **Flag missing error handling** ONLY IF HTTPException isn't raised appropriately for error cases51- **Flag sync in async** ONLY IF the operation is actually blocking (file I/O, network calls, CPU-bound), not just non-async5253## FastAPI Framework Behaviors5455FastAPI + Pydantic handle many concerns automatically:56- Request validation via Pydantic models57- Response serialization via response_model58- Dependency injection for cross-cutting concerns59- Exception handling via exception handlers6061Before flagging "missing" functionality, verify FastAPI isn't handling it.6263## When to Load References6465- Reviewing route definitions → routes.md66- Reviewing dependency injection → dependencies.md67- Reviewing Pydantic models/validation → validation.md68- Reviewing async route handlers → async.md6970## Review Questions71721. Do all routes have explicit response models and status codes?732. Are dependencies injected via Depends() with proper cleanup?743. Do all Pydantic models validate inputs correctly?754. Are all route handlers async and non-blocking?7677## Before Submitting Findings7879Load and follow [review-verification-protocol](../review-verification-protocol/SKILL.md) before reporting any issue.
Run npx skillmds add tools-only/fastapi-code-review in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Reviews FastAPI code for routing patterns, dependency injection, validation, and async handlers. Use when reviewing FastAPI apps, checking APIRouter setup, Depends() usage, or response models. It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tools-only (@tools-only) published this skill. Their other Agent Skills are listed on their SkillMD profile.