tezvyn:

Implement a custom validator for a single Pydantic model field

Source: pydantic.devintermediate

WHAT IT TESTS: Your grasp of Pydantic v2 field validation hooks. ANSWER OUTLINE: Use @field_validator as a classmethod, raise ValueError on failure, return the value. RED FLAG: Validating outside the model or confusing v1 @validator with v2.

WHAT IT TESTS: Whether you understand Pydantic v2's extension points for field-level logic beyond standard type constraints. ANSWER OUTLINE: A strong answer leads with @field_validator as a classmethod, raises ValueError for passwords under 10 characters or missing a digit, returns the cleaned string, and optionally contrasts this with reusable Annotated validators using __get_pydantic_core_schema__.

Read the original → pydantic.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Implement a custom validator for a single Pydantic model field · Tezvyn