Use schemas to validate payloads before business logic runs.

1
2
3
4
5
from pydantic import BaseModel, Field

class CreateTaskRequest(BaseModel):
    title: str = Field(min_length=3, max_length=120)
    priority: int = Field(default=3, ge=1, le=5)

Define a shared error format so frontend clients can handle failures cleanly.

Saved locally to your browser.