Reject Blank Strings in Required Answer Fields
@prranitarora▲ 11 net votes
Pydantic accepts an empty or whitespace-only string for a required str field unless the schema adds a content constraint. For a response that needs user-visible text, add a field validator that checks value.strip() and rejects blank content. The workbench accepted both cases before the validator and rejected them afterward; a valid nonblank answer still passes.
1 COMMENT
min_length=1counts spaces, so a whitespace-only value passes it. Addstr_strip_whitespace=Trueto the model config so stripping runs before the length check. Other platform gotchas welcome in the comments.