{"id":"c7b7d730ba51a2d3","repo":"colinhacks/zod","slug":"not-is-not-supported-in-zod-except-not-fo","errorCode":null,"errorMessage":"not is not supported in Zod (except { not: {} } for never)","messagePattern":"not is not supported in Zod \\(except (.+?) \\} for never\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/zod/src/v4/classic/from-json-schema.ts","lineNumber":153,"sourceCode":"  if (path[0] === defsKey) {\n    const key = path[1];\n    if (!key || !ctx.defs[key]) {\n      throw new Error(`Reference not found: ${ref}`);\n    }\n    return ctx.defs[key]!;\n  }\n\n  throw new Error(`Reference not found: ${ref}`);\n}\n\nfunction convertBaseSchema(schema: JSONSchema.JSONSchema, ctx: ConversionContext): ZodType {\n  // Handle unsupported features\n  if (schema.not !== undefined) {\n    // Special case: { not: {} } represents never\n    if (typeof schema.not === \"object\" && Object.keys(schema.not).length === 0) {\n      return z.never();\n    }\n    throw new Error(\"not is not supported in Zod (except { not: {} } for never)\");\n  }\n  if (schema.unevaluatedItems !== undefined) {\n    throw new Error(\"unevaluatedItems is not supported\");\n  }\n  if (schema.unevaluatedProperties !== undefined) {\n    throw new Error(\"unevaluatedProperties is not supported\");\n  }\n  if (schema.if !== undefined || schema.then !== undefined || schema.else !== undefined) {\n    throw new Error(\"Conditional schemas (if/then/else) are not supported\");\n  }\n  if (schema.dependentSchemas !== undefined || schema.dependentRequired !== undefined) {\n    throw new Error(\"dependentSchemas and dependentRequired are not supported\");\n  }\n\n  // Handle $ref\n  if (schema.$ref) {\n    const refPath = schema.$ref;\n    if (ctx.refs.has(refPath)) {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/colinhacks/zod/blob/912f0f51b0ced654d0069741e7160834dca742ee/packages/zod/src/v4/classic/from-json-schema.ts#L135-L171","documentation":"Thrown by convertBaseSchema when a JSON Schema uses the `not` keyword in any form other than `{ not: {} }`, which the converter maps to z.never(). General negation constraints are not representable in Zod's additive model.","triggerScenarios":"A schema like `{ not: { type: \"string\" } }` (anything except a string), `{ not: { enum: [...] } }`, or `{ not: { const: 0 } }`. Even `{ not: { type: \"object\" } }` is rejected.","commonSituations":"Inheriting schemas authored for Ajv or other validators that fully support `not`; OpenAPI extensions that use `not` to forbid shapes; trying to express 'not one of' constraints.","solutions":["If you intend 'reject everything' use `{ not: {} }`, which converts to z.never().","Replace `not` with an affirmative constraint expressible in Zod: e.g. use `anyOf`/`oneOf` to enumerate allowed shapes, or move the negation into a `.refine()` after conversion.","Strip `not` from the source schema and apply the equivalent check downstream in code."],"exampleFix":"// before\n{ \"not\": { \"type\": \"string\" } } // 'not a string'\n\n// after\n// enumerate allowed types instead, then refine\nconst s = z.any().refine((v) => typeof v !== \"string\", \"must not be a string\");","handlingStrategy":"validation","validationCode":"function assertNoNot(schema: any) {\n  if (schema.not !== undefined && !(typeof schema.not === \"object\" && Object.keys(schema.not).length === 0)) {\n    throw new Error(\"`not` is unsupported; only { not: {} } is allowed\");\n  }\n}","typeGuard":"function isSupportedNot(schema: any): boolean {\n  return schema.not === undefined || (typeof schema.not === \"object\" && Object.keys(schema.not).length === 0);\n}","tryCatchPattern":null,"preventionTips":["Author affirmative schemas (allow-lists) instead of negations.","Move 'not' logic into a post-conversion refine.","Reject schemas with `not` at intake if conversion is required."],"tags":["json-schema","not","unsupported","v4","from-json-schema"],"analyzedSha":"912f0f51b0ced654d0069741e7160834dca742ee","analyzedAt":"2026-08-03T17:41:55.908Z","schemaVersion":2}