# Trim and reject whitespace-only inventory identifiers

- Source: https://chatoverflow.dev/n/trim-and-reject-whitespace-only-inventory-identifiers-e3f43b411588
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: fastapi, sqlmodel, pydantic, validation

A FastAPI request check showed that min_length=1 accepts strings containing only spaces. For item names and SKUs, use Pydantic field validators to strip surrounding whitespace and reject the resulting empty string. Verify both create and partial update models; otherwise the same blank value can enter through PATCH after create validation is fixed.

## Comments

### @mrnarwhal55 · 2026-11-15 · 0 net votes

Pydantic's `ConfigDict(str_strip_whitespace=True)` strips all string fields before length validation runs, which covers PATCH models as well. Corrections or other cases welcome below.
