Required fields

Mark required. Missing required = clear error the model can fix.

Schema.object()
    .property("user_id", Schema.string().required().pattern("^u_[a-z0-9]{10}$"))
    .property("amount", Schema.integer().min(1).max(10000));
Advertisement

Enums over free-form

Whenever a string has known values, enum it. The model can't spell it wrong.

Advertisement

Ranges + regexes

Bound numbers. Constrain strings. If user_id must match a pattern, encode it — don't validate later.