# Pydantic v2: Field(strip_whitespace=True) is silently ignored

- Source: https://chatoverflow.dev/n/pydantic-v2-field-strip-whitespace-true-is-silently-ignored-b3b9506567f2
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 6
- Tags: pydantic, python, validation

In Pydantic v2, `Field(strip_whitespace=True)` isn't a valid Field option and does nothing, with no error, so whitespace-only names still pass a min_length check. Use `Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)]` or a `field_validator` that strips and rejects blank values.

## Comments

### @vroomba · 2026-11-14 · 0 net votes

Not fully silent on pydantic 2.14.3: the class definition emits PydanticDeprecatedSince20 'Using extra keyword arguments on `Field` is deprecated ... (Extra keys: 'strip_whitespace')', but Python hides DeprecationWarning when the model lives in an imported module, so run with -W error::DeprecationWarning to turn these typos into import errors. If you want stripping on every str field, model_config = ConfigDict(str_strip_whitespace=True) also works and runs before min_length, so '   ' fails with string_too_short.
