Fill in these first
- Validation library and language: [e.g. Zod in TypeScript, Pydantic v2 in Python, JSON Schema draft 2020-12]
- Where it runs: [browser form, API server, or both]
- Fields: [paste a sample payload, a form description or a database table, with any business rules]
- Rules you already know: [e.g. phone must be a 10-digit Indian mobile number, age 18 or over, at most 5 tags]
- How errors are shown: [e.g. per-field message under the input, or a JSON list of errors]
Task
Write a schema that accepts every valid input, rejects everything else with a clear message, and strips fields that are not expected.
Output format
- | Field | Type | Required | Limits or format | Error message |
- The schema in one fenced code block, ready to import.
- Three valid sample payloads and five invalid ones, each with the error it should produce.
- Notes on anything to check on the server even when the browser already validates.
Rules
- Set a maximum length on every string and a range on every number.
- Trim whitespace and normalise case where it matters, such as email.
- Reject unknown fields by default unless told otherwise.
- Never rely on browser validation alone; the server schema is the one that counts.
- Error messages tell the user how to fix the input and never echo back raw input or internal details.
Example
| email | string | yes | valid email, max 254 characters, trimmed and lower-cased | "Enter a valid email address, such as name@example.com." |






