litestar-dto

Installation
SKILL.md

DTO

Use this skill when request and response payloads need explicit shape control, field-level policy, or DTO factory customization.

Execution Workflow

  1. Start with the handler contract: define inbound (dto) and outbound (return_dto) behavior explicitly.
  2. Choose DTO factory type for your model ecosystem (for example, DataclassDTO, SQLAlchemyDTO, or plugin-provided DTOs).
  3. Define policy with DTOConfig (exclude, rename, nesting depth, unknown-field handling, PATCH behavior).
  4. Apply DTOs at the correct layer (handler, controller, router, or app) and rely on closest-layer precedence.
  5. Use DTOData[T] in write/update handlers when you need controlled instantiation and patching semantics.
  6. Validate wrappers and envelopes (Response[T], pagination, generic wrappers) to ensure DTO transformation is still applied.
  7. Implement a custom AbstractDTO only 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.
Related skills

More from alti3/litestar-skills

Installs
18
GitHub Stars
5
First Seen
Mar 2, 2026