fastapi-code-review
Skill91 starsChanged 5 days agoApache-2.0View on GitHub
Reviews FastAPI code for routing patterns, dependency injection, Pydantic v2 validation, and async/sync handler safety. Use when reviewing FastAPI apps, checking APIRouter setup, Depends()/Annotated usage, or response models.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- mvilrokx/claude-skillstheir own version, first seen Dec 11, 2025
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- mvilrokx/claude-skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository85 other files it gives its agents.
- AGENTS.mdAGENTS.md
- llms.txtllms.txt
- agent-architecture-analysisSkill
- app-intents-code-reviewSkill
- artifact-analysisSkill
- axum-code-reviewSkill
- brainstorm-beagleSkill
- bubbletea-code-reviewSkill
- cloudkit-code-reviewSkill
- elixir-performance-reviewSkill
- elixir-security-reviewSkill
- elixir-writing-docsSkill
- exdoc-configSkill
- exunit-code-reviewSkill
- fetch-pr-feedbackSkill
- ffi-code-reviewSkill
- fix-llm-artifactsSkill
- fowler-refactoringSkill
- gen-test-planSkill
- go-architectSkill
- go-code-reviewSkill
- go-data-persistenceSkill
- go-testing-code-reviewSkill
- healthkit-code-reviewSkill
- humanize-beagleSkill
- improve-docSkill
- ios-animation-code-reviewSkill
- liveview-code-reviewSkill
- llm-artifacts-detectionSkill
- llm-judgeSkill
- macros-code-reviewSkill
- phoenix-code-reviewSkill
- postgres-code-reviewSkill
- prfaq-beagleSkill
- prometheus-go-code-reviewSkill
- pytest-code-reviewSkill
- quick-planSkill
- react-flow-code-reviewSkill
- react-flowSkill
- react-router-code-reviewSkill
- react-router-v7Skill
- receive-feedbackSkill
- refactor-repoSkill
- resolve-beagleSkill
- respond-pr-feedbackSkill
- review-ai-writingSkill
- review-elixirSkill
- review-frontendSkill
- review-goSkill
- review-iosSkill
- review-llm-artifactsSkill
- review-planSkill
- review-pythonSkill
- review-remix-v2Skill
- review-rustSkill
- review-skillSkill
- review-structureSkill
- review-tuiSkill
- review-verification-protocolSkill
- run-test-planSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 2 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 47
Only flag issues when the context warrants it:
- Very specific: line 49
Flag missing validation: ONLY IF the field isn't already in a Pydantic model or constrained via Query/Path/Body
- Very specific: line 50
Flag missing auth: ONLY IF neither the endpoint nor its APIRouter/FastAPI app applies an auth dependency
- Very specific: line 51
Flag missing error handling: ONLY IF no HTTPException or app exception handler handles the failure case
- Very specific: line 52
Flag blocking in async: ONLY IF an actually blocking operation (sync network I/O, time.sleep, heavy file/CPU work, sync DB driver) runs …
- Very specific: line 56
Run once per FastAPI-related finding, after anchoring file:line for the handler per review-verification-protocol …
- Distinctive: line 88
Before flagging "missing" functionality, verify FastAPI isn't handling it.
- Very specific: line 99
Do all routes specify explicit response models (via response_model= or return-type annotation) and status codes?
- Very specific: line 101
Do all Pydantic v2 models use ConfigDict and validate inputs properly?
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
FastAPI Code Review
Quick Reference
| Issue Type | Reference |
| APIRouter setup, response_model, status codes, lifespan | references/routes.md |
Annotated[..., Depends()], yield deps, pure ASGI middleware | references/dependencies.md |
Pydantic v2 ConfigDict, HTTPException, 422 handling | references/validation.md |
def vs async def, blocking I/O, asyncio.to_thread, background tasks | references/async.md |
Review Checklist
APIRouterwith proper prefix and tags- All routes specify
response_model=or a typed return annotation (-> UserResponse) for validation/OpenAPI - Correct HTTP methods (
GET,POST,PUT,DELETE,PATCH) and status codes (201,204, etc.) - Dependencies use
Annotated[T, Depends(...)](orDepends(...)), not manual calls - Yield dependencies clean up resources in
finally(or viaasync with) - Request/Response models use Pydantic v2 (
ConfigDict,@model_validator,@field_validator) HTTPExceptionincludes explicit status code anddetailasync defhandlers contain no blocking I/O (requests,time.sleep, syncopen(), sync DB); syncdefhandlers are used for sync I/O (run in AnyIO threadpool)BackgroundTasksused for fire-and-forget post-response work- App startup/shutdown uses
lifespancontext manager (not deprecatedon_event) - Middleware uses pure ASGI (
__call__(scope, receive, send)) rather thanBaseHTTPMiddlewarewherecontextvars, streaming, or WebSockets matter
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
- Sync
defroute handlers for sync I/O — FastAPI runsdefhandlers in an AnyIO worker threadpool so they do not block the event loop async defendpoint withoutawait— Valid for non-blocking computations or simple returns- Dependency injection via
Depends()— Sessions and services come fromDepends(), with type inferred from the callable if unannotated - Response model different from DB model — Intentional separation between API schemas and persistence models
BackgroundTasksparameter — Standard pattern for fire-and-forget post-response operations- Direct
request.stateaccess — Standard pattern for middleware-injected or lifespan-initialized state Query/Path/BodyinAnnotated[...]or defaults — FastAPI processes these at runtime- Returning
dictor ORM object from endpoint — Pydantic validates and serializes automatically whenresponse_model=or a return-type annotation 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 or constrained via
Query/Path/Body - Flag missing auth ONLY IF neither the endpoint nor its
APIRouter/FastAPIapp applies an auth dependency - Flag missing error handling ONLY IF no
HTTPExceptionor app exception handler handles the failure case - Flag blocking in async ONLY IF an actually blocking operation (sync network I/O,
time.sleep, heavy file/CPU work, sync DB driver) runs directly inside anasync defhandler or dependency (not inside adefhandler)
Gates (FastAPI-specific)
Run once per FastAPI-related finding, after anchoring file:line for the handler per review-verification-protocol (review-verification-protocol) and before the finding 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=, return-type annotation, and status_code= on that decorator/signature (or note they are absent). | Snippet from those lines or explicit absent with the same file:line. |
Gate 2 — Blocking I/O in async def
| Step | Action | Pass condition |
| 2a | Confirm the handler/dependency is async def and read its full body. | file:line range covering the async def body. |
| 2b | Name each blocking call inside async def (e.g., requests., open(, time.sleep, sync DB/ORM). Do not flag def handlers merely for being sync. | Each blocking 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: Annotated[..., Depends] / 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 / app registration) 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 and
Annotatedparameters - Response serialization/filtering via
response_model=or return-type annotations - Dependency injection (
Depends) for cross-cutting concerns - Exception handling via
@app.exception_handler
Before flagging "missing" functionality, verify FastAPI isn't handling it.
When to Load References
- Reviewing route definitions or lifespan →
references/routes.md - Reviewing dependency injection or middleware →
references/dependencies.md - Reviewing Pydantic v2 models/validation →
references/validation.md - Reviewing
async defvsdefhandlers →references/async.md
Review Questions
- Do all routes specify explicit response models (via
response_model=or return-type annotation) and status codes? - Are dependencies injected via
Annotated[..., Depends()]with proper cleanup? - Do all Pydantic v2 models use
ConfigDictand validate inputs properly? - Are
async defroute handlers free of blocking I/O (or usingdef/asyncio.to_thread()for sync work)?
Before Submitting Findings
- For each FastAPI-related finding, complete Gates (FastAPI-specific) above.
- Load and follow
review-verification-protocol(review-verification-protocol) before reporting any issue.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

