cd /news/ai-tools/12-cursor-rules-that-stop-ai-assista… · home › topics › ai-tools › article
[ARTICLE · art-151744] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

12 Cursor rules that stop AI assistants writing outdated FastAPI code

A developer published a set of 12 Cursor project rules designed to steer AI coding assistants away from outdated FastAPI patterns such as `.dict()`, `orm_mode`, `session.query()` and SQLite-based tests, replacing them with Pydantic v2, SQLAlchemy 2.0 and async conventions. The rules are scoped `.mdc` files in `.cursor/rules/` that load only for matching globs, and the same conventions can be applied to Claude Code via a repo-root `CLAUDE.md`. The author sells a $12 rules pack with seven scoped files, two of which are offered as a free download.

by read1 min views3 publishedOct 17, 2026

AI coding assistants still reach for FastAPI patterns from a few years ago: .dict(), orm_mode, session.query(), HTTPException raised deep inside service code, SQLite in tests. The code runs, but it isn't the code you'd write today.

Cursor's project rules fix most of this. A rule is a small .mdc file in .cursor/rules/ with a glob, so it loads only when you edit matching files:

---
description: "FastAPI routers, dependencies and Pydantic v2 schemas"
globs: src/app/**/router.py,src/app/**/schemas.py,src/app/**/deps.py
alwaysApply: false
---
- One APIRouter(prefix="/<plural-resource>") per feature ...

These are the 12 conventions that made the biggest difference for me.

model_validate, model_dump, ConfigDict, field_validator. Never .dict(), parse_obj, orm_mode, class Config or the v1 validator decorator.response_model`` status_code: 201 for create, 204 for delete. XCreate / XUpdate / XRead. ConfigDict(extra="forbid") so a sneaky "is_admin": true is rejected. Apply updates with model_dump(exclude_unset=True). Mapped[...], mapped_column(), select(). Never session.query() or declarative_base(). async with session.begin():. Repositories never commit. Use async_sessionmaker(expire_on_commit=False). lazy="raise". selectinload() or joinedload(), so there's no hidden IO in async code. MetaData(naming_convention=...) on your BaseAppError subclasses, never HTTPException.{"error": {"code": ..., "message": ...}}. get_settings()``os.environ elsewhere, and keep secrets as SecretStr. text(...).bindparams(). httpx.AsyncClient(transport=ASGITransport(app=app))``app.dependency_overrides after each test. No SQLite stand-in. Drop rules like these into .cursor/rules/, one file per area, with globs that match your layout. For Claude Code, the same conventions work as a short CLAUDE.md at the repo root.

Disclosure: I made a FastAPI rules pack with these conventions written out as 7 scoped .mdc files plus a CLAUDE.md, and I sell it for $12 at codebaserules.com. Two of the files are a free download, no email needed. Everything above works without buying anything. I'd like to hear which of these you'd change.

── more in #ai-tools 4 stories · sorted by recency
── more on @cursor 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/12-cursor-rules-that…] indexed:0 read:1min 2026-10-17 · —