litestar-dto

Enforce explicit inbound and outbound DTO transformations for Litestar handlers.

7|1|Updated Mar 2, 2026
One-click install
npx skills add https://github.com/alti3/litestar-skills --skill litestar-dto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: litestar-dto
Source: https://github.com/alti3/litestar-skills/tree/main/plugins/litestar/skills/litestar-dto
Command: npx skills add https://github.com/alti3/litestar-skills --skill litestar-dto

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Explicitly shaping inbound and outbound API payloads to protect internal models and enforce contract stability.

Core Features & Use Cases

  • Layered DTO configuration with dto and return_dto across handler, controller, router, or app
  • DTOConfig policies for exclude, rename_fields, max_nested_depth, forbid_unknown_fields, and partial updates
  • DTOData for safe create/update with controlled mutation and nested field paths
  • Custom AbstractDTO support when factories can't cover requirements
  • Clear patterns for ensuring consistent DTO-driven transformations across the stack

Quick Start

Define a ReadDTO/WriteDTO pair for your model and attach them to your Litestar endpoint to start enforcing a stable payload contract.

Frequently Asked Questions about litestar-dto

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce explicit inbound and outbound payload transformations in Litestar?

Enforce explicit inbound and outbound payload transformations in Litestar by defining ReadDTO and WriteDTO pairs for your models and attaching them to handlers, controllers, or routers to govern how data enters and leaves your API endpoints.

What is the best way to exclude or rename fields in a Litestar API payload?

Exclude or rename fields in a Litestar API payload by applying DTOConfig policies. DTOConfig allows you to explicitly specify fields to exclude, rename fields, set max nested depth, and forbid unknown fields for strict contract stability.

Can I apply different DTO configurations at the handler, controller, and router layers in Litestar?

You can apply different DTO configurations at the handler, controller, router, or app layers in Litestar. The framework supports layer-specific dto and return_dto definitions, allowing nested field policies to override or refine broader app-level configurations.

How do I handle partial updates and controlled mutations with Litestar DTOs?

Handle partial updates and controlled mutations in Litestar by using the partial parameter within DTOConfig alongside DTOData. DTOData enables safe create and update operations by providing controlled access to inbound data and nested field paths.

When do I need a custom AbstractDTO implementation instead of a factory in Litestar?

You need a custom AbstractDTO implementation in Litestar when standard DTO factories cannot cover your specific payload transformation requirements. Custom AbstractDTO support allows you to define explicit, complex data shaping logic for your API handlers.

Why should I use separate DTOs for reading and writing data in a Litestar backend?

Use separate ReadDTO and WriteDTO configurations in a Litestar backend to protect internal models and enforce contract stability. Explicitly shaping inbound and outbound payloads prevents data overexposure and ensures consistent API transformations across the stack.