Files

GitHub Copilot instructions for FastAPI, SQLAlchemy 2.0 and Pydantic v2

A .github/copilot-instructions.md that steers Copilot toward current FastAPI patterns: SQLAlchemy 2.0 select() style, Pydantic v2 APIs, thin routers with service layers, per-record authorization checks, and pytest with dependency overrides.

File in Engineering by AISkillHub Library

What it does

Copilot has seen years of FastAPI code written for Pydantic v1 and SQLAlchemy 1.x, and it mixes them freely: `session.query()`, `class Config`, `@validator`, `parse_obj`. In a modern codebase those cause deprecation warnings at best and runtime errors at worst. Repository custom instructions let you tell Copilot which versions and patterns this project uses.

**What the instructions enforce**

- **Python 3.11+ style**: `X | None`, built-in generics, full type hints including return types. - **Layout**: thin routers in `app/api/`, business logic in `app/services/` (no FastAPI imports), ORM models and Pydantic schemas in separate packages, tests mirroring the app. - **FastAPI**: `response_model` or return annotations on every route, `Annotated[..., Depends(...)]` dependencies, specific `HTTPException` codes with safe details, and `def` rather than `async def` routes when the database session is synchronous. - **Pydantic v2**: `model_validate`, `model_dump`, `ConfigDict(from_attributes=True)`, `field_validator`; separate create, update and read models; `exclude_unset=True` for partial updates; settings via `pydantic-settings`. - **SQLAlchemy 2.0**: `DeclarativeBase`, `Mapped`, `mapped_column`, `select()` with `session.scalars()`, eager loading to avoid N+1 queries, transactions at the service boundary, Alembic migrations for every model change. - **Security**: per-record authorization checks, no secrets in code or logs, no string-built SQL. - **Tests**: pytest with `TestClient` or `httpx.AsyncClient`, `app.dependency_overrides` instead of patching internals, and 401/403/404/422 paths for each new route.

**What it will not do**

It does not choose your auth scheme, async driver or password hashing library; it tells Copilot to use what the project already has. If your project uses an async SQLAlchemy session, change the `def` versus `async def` rule accordingly.

How to use it

1. Copy the file to `.github/copilot-instructions.md` in your repository (create the `.github` folder if needed). 2. Edit the project layout section to match your real folder names, and remove rules that do not fit (for example, if you use an async session). 3. Commit it. Copilot Chat in supported editors and on GitHub picks up repository custom instructions automatically; check that custom instructions are enabled in your Copilot settings. 4. Verify it is being used: ask Copilot Chat a question about the repo and check whether `.github/copilot-instructions.md` is listed in the references of the response. 5. Keep it short and current. When you upgrade a major dependency, update the matching section.

Files

Save each file at the path shown, relative to your project root.

  • .github/copilot-instructions.md4.1 KB

More files

See all
  • File· EngineeringFree

    CLAUDE.md template for Laravel applications

    A ready-to-fill CLAUDE.md for Laravel projects that gives Claude Code the commands, conventions and guardrails it needs: tests with Pest or PHPUnit, Pint, migrations, Form Requests, policies, queues and config caching rules.

    Coding agentsClaude

    ALAISkillHub Library

  • File· OperationsFree

    Token and cost estimator script for prompts and batch jobs

    A Python script that approximates token counts for prompt files and projects the cost of a batch of requests from prices you supply. Clearly labeled as an estimate, with optional tiktoken counting.

    Coding agents

    ALAISkillHub Library

  • File· ProductFree

    JSON Schema for support ticket triage structured output

    A strict JSON Schema (draft 2020-12) for classifying an inbound support ticket: category, priority, sentiment, language, summary, extracted IDs, human-handoff flag and routing queue. Every field is required and described.

    ChatGPTClaudeCoding agents

    ALAISkillHub Library

Get AISkillHub updates in your inbox.

New features as they ship, AI live chat improvements, and the best new listings in the catalog.

Product updates, new features, and guides. Unsubscribe any time.

GitHub Copilot instructions for FastAPI, SQLAlchemy 2.0 and Pydantic v2 - AI file - AISkillHub.dev