fastapi-code-review
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.
What this skill does
# FastAPI Code Review ## Quick Reference | Issue Type | Reference | |------------|-----------| | APIRouter setup, response_model, status codes | [references/routes.md](references/routes.md) | | Depends(), yield deps, cleanup, shared deps | [references/dependencies.md](references/dependencies.md) | | Pydantic models, HTTPException, 422 handling | [references/validation.md](references/validation.md) | | Async handlers, blocking I/O, background tasks | [references/async.md](references/async.md) | ## Review Checklist - [ ] APIRouter with proper prefix and tags - [ ] All routes specify `response_model` for type safety - [ ] Correct HTTP methods (GET, POST, PUT, DELETE, PATCH) - [ ] Proper status codes (200, 201, 204, 404, etc.) - [ ] Dependencies use `Depends()` not manual calls - [ ] Yield dependencies have proper cleanup - [ ] Request/Response models use Pydantic - [ ] HTTPException with status code and detail - [ ] All route handlers are `async def` - [ ] No blocking I/O (`requests`, `time.sleep`, `open()`) - [ ] Background tasks for non-blocking operations - [ ] No bare `except` in route handlers ## Valid Patterns (Do NOT Flag) These are idiomatic FastAPI patterns that may appear problematic but are correct: - **Pydantic validates request body automatically** - No manual validation needed when using typed Pydantic models as parameters - **Dependency injection for database sessions** - Sessions come from `Depends()`, not passed as function arguments - **HTTPException for all HTTP errors** - FastAPI handles conversion to proper HTTP responses - **Async def endpoint without await** - May be using sync dependencies or simple operations; FastAPI handles this - **Type annotation on Depends()** - This is documentation/IDE support, not a type assertion - **Query/Path/Body defaults** - FastAPI processes these at runtime, not traditional Python defaults - **Returning dict from endpoint** - Pydantic converts automatically if `response_model` is set ## Context-Sensitive Rules Only flag issues when the context warrants it: - **Flag missing validation** ONLY IF the field isn't already in a Pydantic model with validators - **Flag missing auth** ONLY IF the endpoint isn't using `Depends()` with an auth dependency - **Flag missing error handling** ONLY IF HTTPException isn't raised appropriately for error cases - **Flag sync in async** ONLY IF the operation is actually blocking (file I/O, network calls, CPU-bound), not just non-async ## Gates (FastAPI-specific) Run **once per FastAPI-related finding**, after you can anchor **`file:line`** for the handler (see [review-verification-protocol](../review-verification-protocol/SKILL.md)) and **before** the finding text ships. If a step’s pass condition is not met, **do not** assert the finding as written—gather evidence, withdraw, downgrade severity, or rephrase as a question. ### Gate 1 — Route decorator and response surface | Step | Action | **Pass condition** | |------|--------|---------------------| | 1a | Open the handler’s route decorator in the repo (not from memory). | **`file:line`** for `@router.*` / `@app.*` (or the site that registers this handler). | | 1b | Record HTTP method, `response_model=`, and `status_code=` on that decorator (or note they are absent). | **Snippet from that line** or **explicit absent** with the same **`file:line`**. | ### Gate 2 — Blocking or “should be async” | Step | Action | **Pass condition** | |------|--------|---------------------| | 2a | Read the full handler body. | **`file:line` range** covering the body. | | 2b | If claiming blocking I/O: name each blocking call (e.g. `requests.`, `open(`, `time.sleep`, sync DB/ORM). | **Each** call has **`file:line`**, or withdraw the finding if **none** after the read. | ### Gate 3 — Depends, validation, auth | Step | Action | **Pass condition** | |------|--------|---------------------| | 3a | List parameters: `Depends` / `Annotated[..., Depends]`, Pydantic models, `Body`/`Query`/`Path`, `Request`/`Response`. | **Names + mechanism** tied to **`file:line`** on the signature. | | 3b | If claiming missing auth: search the handler file (and its `APIRouter` module if separate) for `Depends`, `Security`, `HTTPBearer`, or project auth dependencies. | **Citation** to an existing hook, or **search result**: paths searched + **N matches** (zero is allowed). | | 3c | If claiming missing validation: confirm the argument is not already a Pydantic model or constrained `Query`/`Path`/`Body`. | **Type/source** with **`file:line`**, or withdraw if validation already applies. | ## FastAPI Framework Behaviors FastAPI + Pydantic handle many concerns automatically: - Request validation via Pydantic models - Response serialization via response_model - Dependency injection for cross-cutting concerns - Exception handling via exception handlers Before flagging "missing" functionality, verify FastAPI isn't handling it. ## When to Load References - Reviewing route definitions → routes.md - Reviewing dependency injection → dependencies.md - Reviewing Pydantic models/validation → validation.md - Reviewing async route handlers → async.md ## Review Questions 1. Do all routes have explicit response models and status codes? 2. Are dependencies injected via Depends() with proper cleanup? 3. Do all Pydantic models validate inputs correctly? 4. Are all route handlers async and non-blocking? ## Before Submitting Findings 1. For each FastAPI-related finding, complete **Gates (FastAPI-specific)** above. 2. Load and follow [review-verification-protocol](../review-verification-protocol/SKILL.md) (Pre-Report checklist and **Verification by Issue Type**) before reporting any issue.
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.