{"record":{"id":"7e82d56fa258d9e2","repo":"vercel/ai","slug":"element-streams-in-enum-mode-functionality-not-s","errorCode":null,"errorMessage":"'element streams in enum mode' functionality not supported.","messagePattern":"'element streams in enum mode' functionality not supported\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/output-strategy.ts","lineNumber":396,"sourceCode":"            value,\n            cause: 'value must be a string in the enum',\n          }),\n        };\n      }\n\n      return {\n        success: true,\n        value: {\n          partial:\n            possibleEnumValues.length > 1 ? result : possibleEnumValues[0],\n          textDelta,\n        },\n      };\n    },\n\n    createElementStream() {\n      // no streaming in enum mode\n      throw new UnsupportedFunctionalityError({\n        functionality: 'element streams in enum mode',\n      });\n    },\n  };\n};\n\nexport function getOutputStrategy<SCHEMA>({\n  output,\n  schema,\n  enumValues,\n}: {\n  output: 'object' | 'array' | 'enum' | 'no-schema';\n  schema?: FlexibleSchema<SCHEMA>;\n  enumValues?: Array<SCHEMA>;\n}): OutputStrategy<any, any, any> {\n  switch (output) {\n    case 'object':\n      return objectOutputStrategy(asSchema(schema!));","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/output-strategy.ts#L378-L414","documentation":"The enum output strategy throws this UnsupportedFunctionalityError because there is no streaming of elements in `output: 'enum'` mode — the result is a single string chosen from a fixed list, so an element stream is meaningless. `streamObject` with enum output exposes `textStream`/`partialObjectStream`, but `elementStream` is explicitly unsupported.","triggerScenarios":"Calling `streamObject({ output: 'enum', enumValues: [...], ... })` and then consuming `result.elementStream`, typically via untyped code, `as any` casts, or generic wrappers that unconditionally read `elementStream`.","commonSituations":"Classification tasks using enum output where a developer reuses array-streaming iteration code; runtime-polymorphic stream handlers that branch on stream shape without checking output mode.","solutions":["For enum mode, await `result.object` or consume `textStream`/`partialObjectStream` instead of `elementStream`.","If you truly need streamed elements, switch to `output: 'array'` with a string enum schema for elements.","Gate any `elementStream` access behind `output === 'array'` in generic code."],"exampleFix":"// before\nconst result = streamObject({ model, prompt, output: 'enum', enumValues: ['a','b'] });\nfor await (const el of result.elementStream) { ... }\n\n// after\nconst result = streamObject({ model, prompt, output: 'enum', enumValues: ['a','b'] });\nconst choice = await result.object; // 'a' | 'b'","handlingStrategy":"validation","validationCode":"// only request elementStream in array mode\nif (options.output !== undefined && options.output !== 'array') {\n  throw new Error('elementStream requires output: \"array\"');\n}","typeGuard":"function isEnumMode(o: unknown): o is 'enum' {\n  return o === 'enum';\n}","tryCatchPattern":"try {\n  for await (const el of result.elementStream) { /* ... */ }\n} catch (e) {\n  if (UnsupportedFunctionalityError.isInstance(e)) {\n    const value = await result.object; // enum result is a single string\n  } else throw e;\n}","preventionTips":["For enum mode, await result.object — never elementStream.","Gate elementStream access on output === 'array' in generic code.","Keep streamObject results typed to surface this at compile time.","Switch to output:'array' with a z.enum element schema if streaming values matters."],"tags":["streaming","enum","unsupported-functionality","api-misuse"],"backgroundTag":"unsupported-functionality-error","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}