- Home
- Skills
- APIs & Backend
- FastAPI Production Rules
Works with the AI Agents you already use
FastAPI Production Rules
Agent skill for production-grade FastAPI: layering, transactions, multi-tenancy, auth, SQLAlchemy async, ArdiQ background tasks, testing and deployment.
Free
FastAPI Production Rules
Example session with this skill installed
Review my FastAPI ticket endpoint: it loads tickets by ID only, trusts organization_id from the body, and logs full request bodies. Give me a prioritized fix plan.
- Read your context and instructions
- Compiled the fastapi production rules
Based on your description, the endpoint has two customer-data access risks and one logging risk. This is a fix plan, not a verified code audit.
Prioritized Fix Plan
| Priority | Finding | Risk | Recommended change |
|---|---|---|---|
| High | Ticket lookup uses only the ticket ID | A signed-in customer could retrieve another customer's ticket if they obtain its ID. | Restrict the lookup to tickets belonging to the authenticated customer's organization. |
| High | The body supplies organization_id | A caller could substitute another organization's ID. | Remove this field from client input and derive the organization from the authenticated account. |
| High | Logs contain full request bodies | Ticket text and other private details may be retained in logs. | Replace body logging with event names, request IDs, and safe diagnostic fields. |
Verification Before Release
- Create tickets for two organizations. Confirm neither account can access the other's tickets.
- Submit an unexpected
organization_idand confirm validation rejects it. - Send a ticket containing private text and confirm the text does not appear in logs.
Next steps
- Share the router, service, input schema, and logging middleware for a code-level review.
- Apply the fixes and run the access-isolation and logging checks before release.
Connects securely to your tools. The creator never sees your data.
About this skill
FastAPI Production Rules
A set of conventions, patterns, and hard rules for building production-grade FastAPI projects.
Structure
SKILL.md # all rules, short examples, checklists
references/
├── toolchain.md # uv, ruff, ty, pyproject.toml, CI
├── app-setup.md # settings, app factory, lifespan, middleware, CORS, OpenAPI
├── errors-and-responses.md # exceptions, handlers, response wrappers, schemas, pagination
├── database.md # SQLAlchemy async, models, transactions, locking, Alembic
├── auth-and-security.md # passwords, JWT, refresh tokens, magic links, roles, rate limits, uploads
├── logging-and-observability.md # structlog, request context, Sentry, OpenTelemetry, health checks
├── background-tasks.md # ArdiQ tasks, idempotency, retries, cron, outbox
├── api-patterns.md # idempotency keys, webhooks, streaming, outbound HTTP, SSRF, caching, audit
├── testing.md # testcontainers, fixtures, tenant-isolation and architecture tests
├── deployment.md # Dockerfile, uvicorn, migrations in the pipeline, probes
└── crud-example.md # a complete domain: model → schemas → service → router → tests
What it covers
- Toolchain: uv, ruff (including FastAPI-specific rules), ty, CI
- Project structure and app factory with lifespan
- Router → Service → Model separation
- One transaction per use case
- Dependency injection with
Annotated - Custom exceptions and one error format for every error
- Typed response wrappers and correct status codes
- Pydantic v2 schemas that prevent mass assignment
- Offset and cursor pagination with stable ordering
- Multi-tenancy and IDOR prevention
- SQLAlchemy 2.0 async: sessions, explicit loading, integrity, locking
- Zero-downtime Alembic migrations
- Configuration with pydantic-settings
- Structured logging with structlog and request IDs
- Auth: argon2, JWT, rotating refresh tokens with reuse detection, magic links
- Role-based authorization
- Rate limiting
- HTTP security: CORS, security headers, SSRF
- File upload validation
- Background tasks with ArdiQ: idempotency, retries, priorities, cron, transactional outbox
- Idempotency keys and webhooks
- Native SSE and JSON Lines streaming (FastAPI ≥ 0.135)
- Testing with real Postgres, tenant-isolation and architecture tests
- Health checks, Sentry, OpenTelemetry
- Docker and deployment
- Naming conventions
- FastAPI gotchas
- Security and code review checklists
Stack
Examples use PostgreSQL + SQLAlchemy 2.0 async + Pydantic v2 + ArdiQ + Redis, but every principle applies to any ORM or task queue.
Related
How I structure FastAPI projects in production — and why — the post explaining the reasoning behind these rules.
The Python Toolchain I Use in Production: uv, ruff, and ty - another post explaining why i use all the astral stack (uv, ruff and ty)
How to use
Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scanned
Verified clean 14 days ago
- Free to download with an account
Requires