fastapi-errors

An error-handling pattern for FastAPI services, the Python framework used to build web APIs, with shared application exceptions and consistent JSON error responses.

In plain words
What is it for?
Use it when designing service-layer failures, adding domain errors, handling API responses, or building a FastAPI service.
Why use it?
It prevents service code from handling HTTP errors inconsistently and keeps unexpected failures from exposing poor diagnostics. Error logging and response formatting are centralised.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/robhowley/py-pit-skills/fastapi-errors
Any agent
npx skills add robhowley/py-pit-skills --skill fastapi-errors
Clone the repo
git clone --depth 1 https://github.com/robhowley/py-pit-skills

Made for: Claude Code, Codex.

Per session 37 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,075 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00037 $0.02075
Opus 5 $0.00018 $0.01038
Sonnet 5 $0.00007 $0.00415
Haiku 4.5 $0.00004 $0.00208

Measured 2d ago against content hash 789ac9f64f50, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

fastapi-errors scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/fastapi-errors/SKILL.md · 341 lines

How it starts

The opening of the file, as written. The whole thing — 341 lines — stays where its author put it; the contents beside it link to each section on GitHub.

fastapi-errors

Defines a simple, consistent error architecture for FastAPI backend services.

This skill standardizes the flow:

service/domain failure
→ application exception
→ global FastAPI exception handler
→ consistent JSON response

The goal is to prevent common FastAPI problems:

  • HTTPException raised deep in service logic
  • inconsistent error response formats
  • duplicated status code logic
  • domain failures implemented with builtin exceptions
  • unexpected exceptions leaking poor diagnostics

Apply this Skill When

Apply when the user:

  • asks how to structure FastAPI error handling
  • is adding domain exceptions
  • is designing service-layer failures
  • is implementing API error responses
  • is building a new FastAPI service
  • is adding new domain errors in an existing repo

Do not apply when:

  • the task is unrelated to application error handling
  • the user explicitly wants a different architecture

Base Exception

The fastapi-init skill scaffolds a minimal version of this class. This skill defines the complete pattern. If both are present, this skill's version is authoritative.

The service defines one base exception for intentional application failures.

Preferred naming pattern:

<PackageName>Error

Examples:

BillingError
UserServiceError
InventoryError

If the package name cannot be determined, use:

AppError

Define all exceptions in a single module. In fastapi-init projects this is core/exceptions.py. In other layouts, exceptions.py at the package root is typical. Do not scatter them across feature files.

Example base implementation:

class AppError(Exception):
    status_code = 500
    detail: str = "An unexpected error occurred."

    def __init__(self, detail: str | None = None, status_code: int | None = None, **context):
        self.detail = detail if detail is not None else self.__class__.detail
        self.status_code = status_code if status_code is not None else self.__class__.status_code
        self.context = context
        super().__init__(self.detail)

    def __str__(self) -> str:
        return self.detail

Read the full file on GitHub · 341 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 341 lines · 37 tokens per session scan A 789ac9f64f50

Subscribe to this mod's changes

fastapi-errors is a skill published in the GitHub repository robhowley/py-pit-skills (5 stars, last pushed 5mo ago), licensed MIT. It adds 37 tokens to every session and 2,075 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

database

Relational database authority — PostgreSQL, async ORM (SQLAlchemy 2 / asyncpg), Alembic schema migrations, Supabase Python and JS clients, query optimisation, index strategy, connection pooling, transaction patterns, and bulk operations across Python and Node stacks.

LuuOW/meridian-mcp · 54 tokens

FastAPI Customer Support Tech Enablement

Comprehensive FastAPI skill for building modern Python web APIs with focus on customer support systems, ticket management, real-time chat, and backend operations.

manutej/luxor-claude-marketplace · 36 tokens

SQLAlchemy ORM Expert

Comprehensive SQLAlchemy skill for customer support tech enablement, covering ORM patterns, session management, query optimization, async operations, and PostgreSQL integration.

manutej/luxor-claude-marketplace · 34 tokens

fastapi-endpoint

Plan and build production-ready FastAPI endpoints with async SQLAlchemy, Pydantic v2 models, dependency injection for auth, and pytest tests. Uses interview-driven planning to clarify data models, authentication method, pagination strategy, and caching before writing any code.

alirezaebrahimi5/ai-senior-engineer-template · 56 tokens

load-github-action-thread

Download retained Codex GitHub Action thread artifacts and load their rollout history into the local Codex app. Use when asked to open, load, import, resume, or inspect a Codex automation thread from a GitHub Actions run or a related GitHub issue or pull request.

astral-sh/uv · 62 tokens

datamodel-code-generator

Use this skill when the user wants Python data models, Pydantic models, dataclasses, TypedDicts, msgspec structs, or type-safe Python classes generated from OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON/YAML/CSV sample data, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro, or existing Python model objects.…

koxudaxi/datamodel-code-generator · 147 tokens