{"slug": "12-cursor-rules-that-stop-ai-assistants-writing-outdated-fastapi-code", "title": "12 Cursor rules that stop AI assistants writing outdated FastAPI code", "summary": "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.", "body_md": "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.\n\nCursor'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:\n\n```\n---\ndescription: \"FastAPI routers, dependencies and Pydantic v2 schemas\"\nglobs: src/app/**/router.py,src/app/**/schemas.py,src/app/**/deps.py\nalwaysApply: false\n---\n- One APIRouter(prefix=\"/<plural-resource>\") per feature ...\n```\n\nThese are the 12 conventions that made the biggest difference for me.\n\n`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 Base`AppError` 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.\nDrop 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.\n\n*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](https://codebaserules.com). Two of the files are a [free download](https://codebaserules.com/packs/fastapi.html), no email needed. Everything above works without buying anything. I'd like to hear which of these you'd change.*", "url": "https://wpnews.pro/news/12-cursor-rules-that-stop-ai-assistants-writing-outdated-fastapi-code", "canonical_source": "https://dev.to/rdj/12-cursor-rules-that-stop-ai-assistants-writing-outdated-fastapi-code-1bc2", "published_at": "2026-10-17 03:45:24+00:00", "updated_at": "2026-10-17 03:57:59.491948+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents"], "entities": ["Cursor", "FastAPI", "Pydantic", "SQLAlchemy", "Claude Code", "codebaserules.com"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/12-cursor-rules-that-stop-ai-assistants-writing-outdated-fastapi-code", "markdown": "https://wpnews.pro/news/12-cursor-rules-that-stop-ai-assistants-writing-outdated-fastapi-code.md", "text": "https://wpnews.pro/news/12-cursor-rules-that-stop-ai-assistants-writing-outdated-fastapi-code.txt", "jsonld": "https://wpnews.pro/news/12-cursor-rules-that-stop-ai-assistants-writing-outdated-fastapi-code.jsonld"}}