{"record":{"id":"8ad53f977217baa3","repo":"vercel/ai","slug":"google-does-not-support-this-json-schema-enum-enu","errorCode":null,"errorMessage":"Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type.","messagePattern":"Google does not support this JSON Schema enum\\. Enum values must share one supported primitive type and match the schema type\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/google/src/convert-json-schema-to-openapi-schema.ts","lineNumber":364,"sourceCode":"  if (values.length > 0 && values.every(value => value === null)) {\n    const typeAllowsNull =\n      type === undefined ||\n      type === 'null' ||\n      (Array.isArray(type) && type.includes('null'));\n\n    if (typeAllowsNull) {\n      result.type = 'null';\n      if (Array.isArray(type)) {\n        delete result.anyOf;\n      }\n      return;\n    }\n  }\n\n  const enumType = getEnumType({ values: enumValues, type });\n\n  if (enumType === undefined) {\n    throw new UnsupportedFunctionalityError({\n      functionality: 'JSON Schema enum with mixed or unsupported values',\n      message:\n        'Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type.',\n    });\n  }\n\n  result.type = enumType;\n\n  // The earlier type-array conversion created anyOf. The enum gives us one\n  // concrete value type, so store that type directly.\n  if (Array.isArray(type)) {\n    delete result.anyOf;\n  }\n\n  if (nullable) {\n    result.nullable = true;\n  }\n","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google/src/convert-json-schema-to-openapi-schema.ts#L346-L382","documentation":"Google's function-calling schema format requires enum values to be a homogeneous list of one supported primitive type (string, number, integer, boolean) that also matches the declared schema `type`. Mixed-type enums (e.g. ['red', 1, true]) or enums whose values don't match `type` cannot be represented and throw this error in addEnumToSchema.","triggerScenarios":"A zod schema like z.enum(['a', 1]) (mixed types), z.union([z.literal('x'), z.literal(2)]), or a JSON Schema enum whose values mix strings/numbers/objects/arrays/null, converted for a Google model's tool parameters.","commonSituations":"Ports of tool schemas from OpenAI/Anthropic (which tolerate heterogeneous enums); legacy APIs with status codes mixing numbers and strings; schemas hand-written with null mixed into enum lists.","solutions":["Make all enum values the same primitive type (e.g. all strings: '1', '2' instead of 1, 2).","If the declared `type` exists, ensure the enum values match it (numeric enum -> type 'number'/'integer').","Replace the enum with a plain typed field plus a description listing allowed values."],"exampleFix":"// before\nz.union([z.literal('active'), z.literal(1)])\n// after\nz.enum(['active', 'one']) // or all numeric literals","handlingStrategy":"validation","validationCode":"function enumIsHomogeneous(schema) {\n  if (!Array.isArray(schema.enum)) return true;\n  const types = new Set(schema.enum.map(v => v === null ? 'null' : Array.isArray(v) ? 'array' : typeof v));\n  if (types.size > 1) return false;\n  if (schema.type) return [...types].every(t => t === schema.type || (schema.type === 'integer' && t === 'number'));\n  return true;\n}","typeGuard":"function isGoogleSafeEnum(schema) {\n  if (!Array.isArray(schema.enum) || schema.enum.length === 0) return true;\n  const first = typeof schema.enum[0];\n  return ['string', 'number', 'boolean'].includes(first) && schema.enum.every(v => typeof v === first);\n}","tryCatchPattern":"try {\n  await generateText({ model: googleModel, tools });\n} catch (e) {\n  if (e?.message?.includes('JSON Schema enum')) {\n    // coerce enum to uniform strings and retry\n  } else throw e;\n}","preventionTips":["Use z.enum<string>([...]) with string-only literals for Google tools.","Normalize numeric/status-code enums to strings at the schema boundary.","Add a unit test converting each tool schema before release."],"tags":["google","json-schema","enum","schema-conversion"],"backgroundTag":"mixed-enum-types-unsupported","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}