Field Validation

noun

say it: “feeld val-ih-DAY-shun” /fiːld ˌvælɪˈdeɪʃən/

Rules on a Pydantic model's fields, added with Field(), such as a minimum length, a maximum value or a pattern the text must match.

What is Field Validation?

Pydantic's Field() adds rules to a model field: minimum and maximum values, lengths, patterns and descriptions.

class ReviewIn(BaseModel):
    stars: int = Field(ge=1, le=5)
    comment: str = Field(max_length=500)

In a sentence

  • “max_length=80 is field validation on the name.”
  • “Field validation with ge=18 refused an applicant who was 16.”

Level: Journeyman · More FastAPI terms at this level

Updated