{"record":{"id":"48d53b3bcafad1c7","repo":"vercel/ai","slug":"element-streams-in-object-mode-functionality-not","errorCode":null,"errorMessage":"'element streams in object mode' functionality not supported.","messagePattern":"'element streams in object mode' functionality not supported\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/output-strategy.ts","lineNumber":127,"sourceCode":"  async validatePartialResult({ value, textDelta }) {\n    return {\n      success: true,\n      value: {\n        // Note: currently no validation of partial results:\n        partial: value as DeepPartial<OBJECT>,\n        textDelta,\n      },\n    };\n  },\n\n  async validateFinalResult(\n    value: JSONValue | undefined,\n  ): Promise<ValidationResult<OBJECT>> {\n    return safeValidateTypes({ value, schema });\n  },\n\n  createElementStream() {\n    throw new UnsupportedFunctionalityError({\n      functionality: 'element streams in object mode',\n    });\n  },\n});\n\nconst arrayOutputStrategy = <ELEMENT>(\n  schema: Schema<ELEMENT>,\n): OutputStrategy<ELEMENT[], ELEMENT[], AsyncIterableStream<ELEMENT>> => {\n  return {\n    type: 'array',\n\n    // wrap in object that contains array of elements, since most LLMs will not\n    // be able to generate an array directly:\n    // possible future optimization: use arrays directly when model supports grammar-guided generation\n    jsonSchema: async () => {\n      // keep root-level definitions available to root-relative references:\n      const {\n        $schema: _$schema,","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/output-strategy.ts#L109-L145","documentation":"This UnsupportedFunctionalityError is thrown by the object output strategy when an element stream is requested while `streamObject` runs in the default `output: 'object'` mode. Element streams only exist for array outputs, because there are no per-element items to emit from a single object. The strategy intentionally rejects the call instead of returning a stub stream.","triggerScenarios":"Calling `streamObject({ output: 'object', schema, ... })` (or omitting `output`) and then iterating `result.elementStream`. Happens via `as any` casts, untyped JS callers, generic wrapper helpers that always expose `elementStream`, or copy-pasted streaming code from an array-mode example.","commonSituations":"Copy-pasting array-mode streaming code into object-mode code; generic response handlers that conditionally read `elementStream` regardless of output mode; JavaScript projects without type checking.","solutions":["Use `output: 'array'` with a schema for the element type if you need `elementStream`.","In object mode, consume `partialObjectStream`, `object`, or `textStream` instead of `elementStream`.","Fix types (`as any` removal) so the compiler flags `elementStream` access in object mode."],"exampleFix":"// before\nconst result = streamObject({ model, prompt, schema });\nfor await (const el of result.elementStream) { ... }\n\n// after\nconst result = streamObject({\n  model,\n  prompt,\n  output: 'array',\n  schema: z.object({ name: z.string() }),\n});\nfor await (const el of result.elementStream) { ... }","handlingStrategy":"type-guard","validationCode":"// only iterate elementStream for array outputs\nconst result = streamObject({ model, prompt, output: mode, schema });\nif (mode !== 'array') console.warn('elementStream unavailable in', mode);","typeGuard":"function hasElementStream(r: unknown): r is { elementStream: AsyncIterable<unknown> } {\n  return typeof r === 'object' && r !== null && 'elementStream' in r;\n}","tryCatchPattern":"try {\n  for await (const el of result.elementStream) { /* ... */ }\n} catch (e) {\n  if (UnsupportedFunctionalityError.isInstance(e)) {\n    const obj = await result.object; // fallback for object mode\n  } else throw e;\n}","preventionTips":["Keep streamObject calls strongly typed; avoid `as any`.","Use output:'array' with an element schema when streaming elements.","In object mode use `await result.object` or partialObjectStream.","Don't copy array-mode iteration code into object-mode handlers."],"tags":["streaming","object-mode","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"}