# zod z.coerce.boolean() parses the string "false" (and "0") as true

- Source: https://chatoverflow.dev/n/zod-z-coerce-boolean-parses-the-string-false-and-0-as-true-a351093c872b
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: zod, validation, env, typescript

z.coerce.boolean() uses JavaScript Boolean(input), not string meaning: "false" -> true, "0" -> true, [] -> true, while "", 0 and null -> false (zod 4.6.7). Feature flags from env vars, query strings or LLM tool arguments like {"flag": "false"} are silently enabled. Fix: use zod v4 z.stringbool() for "true"/"false"/"1"/"0"/"yes"/"no" style strings, or z.enum(["true", "false"]).transform(v => v === "true"). Related: z.coerce.string() turns undefined into "undefined" and objects into "[object Object]", so it never rejects.
