agentleFS
existential-birdsexistential-birds/beagle/skills/fastapi-code-review/SKILL.md

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

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
  1. Distinctive:

    Only flag issues when the context warrants it:

    line 47
  2. Very specific:

    Flag missing validation: ONLY IF the field isn't already in a Pydantic model or constrained via Query/Path/Body

    line 49
  3. Very specific:

    Flag missing auth: ONLY IF neither the endpoint nor its APIRouter/FastAPI app applies an auth dependency

    line 50
  4. Very specific:

    Flag missing error handling: ONLY IF no HTTPException or app exception handler handles the failure case

    line 51
  5. Very specific:

    Flag blocking in async: ONLY IF an actually blocking operation (sync network I/O, time.sleep, heavy file/CPU work, sync DB driver) runs …

    line 52
  6. Very specific:

    Run once per FastAPI-related finding, after anchoring file:line for the handler per review-verification-protocol …

    line 56
  7. Distinctive:

    Before flagging "missing" functionality, verify FastAPI isn't handling it.

    line 88
  8. Very specific:

    Do all routes specify explicit response models (via response_model= or return-type annotation) and status codes?

    line 99
  9. Very specific:

    Do all Pydantic v2 models use ConfigDict and validate inputs properly?

    line 101

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

FastAPI Code Review

Quick Reference

Issue TypeReference
APIRouter setup, response_model, status codes, lifespanreferences/routes.md
Annotated[..., Depends()], yield deps, pure ASGI middlewarereferences/dependencies.md
Pydantic v2 ConfigDict, HTTPException, 422 handlingreferences/validation.md
def vs async def, blocking I/O, asyncio.to_thread, background tasksreferences/async.md

Review Checklist

  • APIRouter with 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(...)] (or Depends(...)), not manual calls
  • Yield dependencies clean up resources in finally (or via async with)
  • Request/Response models use Pydantic v2 (ConfigDict, @model_validator, @field_validator)
  • HTTPException includes explicit status code and detail
  • async def handlers contain no blocking I/O (requests, time.sleep, sync open(), sync DB); sync def handlers are used for sync I/O (run in AnyIO threadpool)
  • BackgroundTasks used for fire-and-forget post-response work
  • App startup/shutdown uses lifespan context manager (not deprecated on_event)
  • Middleware uses pure ASGI (__call__(scope, receive, send)) rather than BaseHTTPMiddleware where contextvars, 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 def route handlers for sync I/O — FastAPI runs def handlers in an AnyIO worker threadpool so they do not block the event loop
  • async def endpoint without await — Valid for non-blocking computations or simple returns
  • Dependency injection via Depends() — Sessions and services come from Depends(), with type inferred from the callable if unannotated
  • Response model different from DB model — Intentional separation between API schemas and persistence models
  • BackgroundTasks parameter — Standard pattern for fire-and-forget post-response operations
  • Direct request.state access — Standard pattern for middleware-injected or lifespan-initialized state
  • Query/Path/Body in Annotated[...] or defaults — FastAPI processes these at runtime
  • Returning dict or ORM object from endpoint — Pydantic validates and serializes automatically when response_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/FastAPI app applies an auth dependency
  • Flag missing error handling ONLY IF no HTTPException or 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 an async def handler or dependency (not inside a def handler)

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

StepActionPass condition
1aOpen the handler's route decorator in the repo (not from memory).file:line for @router.* / @app.* (or the site that registers this handler).
1bRecord 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

StepActionPass condition
2aConfirm the handler/dependency is async def and read its full body.file:line range covering the async def body.
2bName 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

StepActionPass condition
3aList parameters: Annotated[..., Depends] / Depends, Pydantic models, Body/Query/Path, Request/Response.Names + mechanism tied to file:line on the signature.
3bIf 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).
3cIf 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 Annotated parameters
  • 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 def vs def handlers → references/async.md

Review Questions

  1. Do all routes specify explicit response models (via response_model= or return-type annotation) and status codes?
  2. Are dependencies injected via Annotated[..., Depends()] with proper cleanup?
  3. Do all Pydantic v2 models use ConfigDict and validate inputs properly?
  4. Are async def route handlers free of blocking I/O (or using def / asyncio.to_thread() for sync work)?

Before Submitting Findings

  1. For each FastAPI-related finding, complete Gates (FastAPI-specific) above.
  2. Load and follow review-verification-protocol (review-verification-protocol) before reporting any issue.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.