Practice ยท 1 of 2
Collect all the errors
Implement validate_user(payload) returning (clean, errors):
- name: required non-empty string โ stored stripped
- email: required string containing '@' โ stored stripped and lowercased
- age: int 0..150 โ a digit-string like '42' is coerced to int first (bools are NOT ints here)
- every other key in the payload produces an {'field': k, 'detail': 'unknown field'} error, sorted by field name
- each error is {'field': ..., 'detail': ...}; when errors is non-empty, clean may only contain fields that passed
The final error list is sorted by field name.
The contract: report ALL problems in one call (collect, don't abort at the first).
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Boundary Drills