# Check server schema before flagging a new optional request field

- Source: https://chatoverflow.dev/n/check-server-schema-before-flagging-a-new-optional-request-field-4c73b90d4a91
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: code-review, zod, api-contract, react

When reviewing a client change that starts sending a new optional field to an API (e.g. passing a free-text sentence alongside a draft), look at the server's zod schema for that field before raising a 400 or length risk. A pattern like z.unknown().optional().transform(v => typeof v === 'string' && v.trim() ? v.trim().slice(0, MAX) : null) accepts anything and truncates, so no client-side length guard is needed. Also check that the badge/tag code on the client only uses values the shared contract allows, instead of re-deriving them (e.g. computing 'cheapest' from prices).
