06-dto-and-validation

Define allowlisted DTOs with separate create and update validation contracts.

Updated Mar 9, 2026
One-click install
npx skills add https://github.com/kennypallchizaca-coder/agentic-full-stack-skills --skill 06-dto-and-validation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: 06-dto-and-validation
Source: https://github.com/kennypallchizaca-coder/agentic-full-stack-skills/tree/main/skills-backend/06-dto-and-validation
Command: npx skills add https://github.com/kennypallchizaca-coder/agentic-full-stack-skills --skill 06-dto-and-validation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Input validation is a security boundary, not optional polish. A DTO (Data Transfer Object) is specifically designed to carry data across layers — it is not a domain model and not a persistence entity. This skill focuses on allowlisting fields, validating types and formats, and enforcing safe input before it touches business logic.

Core Features & Use Cases

  • Separate create, update, and query contracts to enforce different validation rules.
  • Prevent client from setting protected fields like id, role, createdAt, or updatedAt.
  • Provide deterministic, per-field validation errors at the boundary to improve API reliability.

Quick Start

Define separate CreateDto and UpdateDto contracts, exclude fields like id, role, createdAt, and updatedAt, and wire controller-level validation to return 400 on invalid input.

Frequently Asked Questions about 06-dto-and-validation

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

FAQPage Schema
How do I prevent clients from setting protected fields like id or role in API input?

Create separate create and update DTOs to enforce different validation rules for each operation. This approach provides deterministic, per-field validation errors at the boundary while keeping validation layered across DTO, service, and data store.

Why do I need separate DTOs for create and update operations?

Separate create and update DTOs enforce different validation rules for each operation. This allows you to require specific fields on creation while making them optional on update, returning deterministic 400 errors with per-field details for invalid input.

How do I return deterministic 400 errors with per-field validation details?

Wire controller-level validation to your allowlisted DTOs to return deterministic 400 errors with per-field details. This keeps validation layered across the DTO, service, and data store, improving API reliability by rejecting invalid input at the boundary.

What is the difference between a DTO and a domain model for input validation?

A DTO is specifically designed to carry data across layers and enforce input validation, not to represent a domain model or persistence entity. It focuses on allowlisting fields, validating types and formats, and enforcing safe input before data touches business logic.

When should I enforce input validation at the API boundary?

Input validation is a security boundary, not optional polish, and should be enforced before data touches business logic. Define allowlisted DTOs that declare accepted fields and exclude sensitive ones to provide deterministic, per-field validation errors at the boundary.