#6634·zod

fromJSONSchema silently drops assertions alongside enum/const, required keys outside properties, and typeless keywords

Author: mleglsCreated Sep 29, 2026Updated Sep 29, 2026

fromJSONSchema silently drops some keywords depending on which conversion branch wins, so the resulting schema accepts values the JSON Schema rejects. Three cases, still present in 4.6.5:

Reproduce

typescript
import { z } from "zod";

// 1. enum or const + type-specific keywords: the assertion is dropped
z.fromJSONSchema({ type: "string", enum: ["a"], minLength: 2 }).safeParse("a").success; // true — should be false
z.fromJSONSchema({ type: "string", const: "a", minLength: 2 }).safeParse("a").success; // true — should be false
z.fromJSONSchema({ type: "number", enum: [1, 5], minimum: 3 }).safeParse(1).success;   // true — should be false

// 2. required naming a key not listed in properties
z.fromJSONSchema({ type: "object", required: ["x"] }).safeParse({}).success; // true — should be false

// 3. type-specific keywords without `type`
z.fromJSONSchema({ minLength: 2 }).safeParse("a").success; // true — should be false
// (per JSON Schema, minLength applies to any string instance)

For contrast, { type: "string", minLength: 2 } and { type: "object", properties: { x: {} }, required: ["x"] } both reject correctly.

Where it comes from (src/v4/classic/from-json-schema.ts)

  1. convertBaseSchema handles enum first and returns a literal/enum schema, so the type switch that applies minLength, pattern, minimum, etc. never runs. const has the same early return just below it.
  2. The "object" case only builds required into the shape for keys in properties; keys that appear only in required impose nothing.
  3. With no type, convertBaseSchema returns z.any() (“No type specified - empty schema”), even when the schema carries assertions that apply conditionally to instances of a given type.

Expected

Every recognized assertion keyword constrains the result, whichever branch builds the base schema, or conversion throws for combinations it doesn't support rather than weakening them silently. Similar per-keyword gaps were fixed in #6463, #6494 and #6198.

Context

We validate tool inputs declared by untrusted authors with fromJSONSchema, so a silently dropped assertion is a validation hole rather than a cosmetic difference. We currently work around it by rejecting these schema shapes before conversion.