litestar-dto
DTO
Use this skill when request and response payloads need explicit shape control, field-level policy, or DTO factory customization.
Execution Workflow
- Start with the handler contract: define inbound (
dto) and outbound (return_dto) behavior explicitly. - Choose DTO factory type for your model ecosystem (for example,
DataclassDTO,SQLAlchemyDTO, or plugin-provided DTOs). - Define policy with
DTOConfig(exclude, rename, nesting depth, unknown-field handling, PATCH behavior). - Apply DTOs at the correct layer (handler, controller, router, or app) and rely on closest-layer precedence.
- Use
DTOData[T]in write/update handlers when you need controlled instantiation and patching semantics. - Validate wrappers and envelopes (
Response[T], pagination, generic wrappers) to ensure DTO transformation is still applied. - Implement a custom
AbstractDTOonly when factory DTOs cannot express required behavior.
Implementation Rules
- Keep read and write DTOs separate when policies differ.
- Keep DTO configuration explicit and reviewable; avoid implicit field exposure.
- Treat nested serialization depth as an API and performance control, not a default.
More from alti3/litestar-skills
litestar-responses
Build Litestar responses with typed return values, explicit Response containers, layered response classes, headers, cookies, status-code control, redirects, files, streams, server-sent events, ASGI app returns, and background tasks. Use when shaping outbound HTTP behavior, correcting response contracts, or choosing the right Litestar response primitive. Do not use for request parsing, validation, or authentication policy design.
22litestar-logging
Configure Litestar logging with `LoggingConfig`, `queue_listener`, exception logging policy, selective stack-trace suppression, standard logging, picologging, Structlog, and custom logging config subclasses. Use when establishing or refactoring application logging behavior, request-level logs, or production-safe error logging in Litestar. Do not use for metrics/tracing instrumentation or exception-response contract design.
22litestar-authentication
Implement Litestar authentication with custom authentication middleware, built-in security backends, JWT and session flows, route inclusion and exclusion rules, and typed auth context on `Request` / `ASGIConnection`. Use when establishing identity, issuing or validating credentials, or attaching authenticated user context in Litestar. Do not use for generic request parsing, broad security audits, or unrelated transport concerns.
22litestar-middleware
Design and apply Litestar middleware for cross-cutting concerns such as CORS, CSRF, allowed-host checks, compression, rate limiting, logging, sessions, request enrichment, policy enforcement, and custom ASGI pipeline control. Use when behavior must wrap broad route sets consistently across the ASGI stack. Do not use for route-specific business rules, simple response mutation better handled by lifecycle hooks, or auth/guard policy work that belongs in security-focused skills.
20litestar-routing
Design and implement Litestar routing with app/router/controller composition, handler decorators, path and parameter modeling, route indexing/reverse lookups, ASGI mounting, and layered route metadata. Use when creating or refactoring endpoint topology and URL contracts. Do not use for purely internal service logic unrelated to HTTP route structure.
18litestar-openapi
Configure Litestar OpenAPI schema generation and documentation UX with `OpenAPIConfig`, route-level schema metadata, schema generation controls, operation customization, UI render plugins, and documentation endpoint strategy. Use when API contract and docs quality must be implemented or corrected, especially for request, auth, and metrics surfaces. Do not use for runtime business logic changes unrelated to schema or documentation.
17