Skip to content

[AI_TypeValidationError] Bedrock stream: validation error when citations enabled #9101

Closed

Description

@kamilKamilson

Description

Expected Behavior

Streaming with citations: { enabled: true } should return a citation delta without validation errors.

Actual Behavior

Fails validation with AI_TypeValidationError because citation is not part of the union in BedrockStreamSchema.
The Bedrock response itself is valid and usable — the error only appears in server logs.

_TypeValidationError [AI_TypeValidationError]: Type validation failed: Value: {"contentBlockDelta":{"contentBlockIndex":3,"delta":{"citation":{"location":{"documentPage":{"documentIndex":0,"end":2,"start":1}},"sourceContent":[{"text":"CONTENT_OF_PDF"}],"title":"document-1"}}}}.
Error message: [{"code":"invalid_union","errors":[[{"expected":"string","code":"invalid_type","path":["text"],"message":"Invalid input: expected string, received undefined"}],[{"expected":"object","code":"invalid_type","path":["toolUse"],"message":"Invalid input: expected object, received undefined"}],[{"expected":"object","code":"invalid_type","path":["reasoningContent"],"message":"Invalid input: expected object, received undefined"}],[{"expected":"object","code":"invalid_type","path":["reasoningContent"],"message":"Invalid input: expected object, received undefined"}],[{"expected":"object","code":"invalid_type","path":["reasoningContent"],"message":"Invalid input: expected object, received undefined"}]],"path":["contentBlockDelta","delta"],"message":"Invalid input"}]
    at Object.validate (/src/node_modules/@ai-sdk/provider-utils/src/validator.ts:69:18)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async safeValidateTypes (/src/node_modules/@ai-sdk/provider-utils/src/validate-types.ts:64:20)
    at async Object.transform (/src/node_modules/@ai-sdk/amazon-bedrock/src/bedrock-event-stream-response-handler.ts:81:48)
    at async transformStreamDefaultControllerPerformTransform (node:internal/webstreams/transformstream:527:12) {
  cause: [
    {
      code: 'invalid_union',
      errors: [Array],
      path: [Array],
      message: 'Invalid input'
    }
  ],
  value: { contentBlockDelta: { contentBlockIndex: 3, delta: [Object] } },
  [Symbol(vercel.ai.error)]: true,
  [Symbol(vercel.ai.error.AI_TypeValidationError)]: true
}

Minimal reproduction

const stream = await client.streamText({
  model: createAmazonBedrock({...})
  messages: [
    {
      role: "user",
      content: [
        {
          data: PDF_BUFFER,
          mediaType: "application/pdf",
          type: "file",
          providerOptions: {
            bedrock: {
              citations: { enabled: true },
            },
          },
        },
      ],
    },
  ],
});

Proposed Solution

Extend BedrockStreamSchema to include citation as a valid delta type:

var BedrockStreamSchema = import_v43.z.object({
  contentBlockDelta: import_v43.z.object({
    contentBlockIndex: import_v43.z.number(),
    delta: import_v43.z.union([
      // add validation here
      import_v43.z.object({ text: import_v43.z.string() }),
      import_v43.z.object({ toolUse: import_v43.z.object({ input: import_v43.z.string() }) }),
      import_v43.z.object({
        reasoningContent: import_v43.z.object({ text: import_v43.z.string() })
      }),
      import_v43.z.object({
        reasoningContent: import_v43.z.object({
          signature: import_v43.z.string()
        })
      }),
      import_v43.z.object({
        reasoningContent: import_v43.z.object({ data: import_v43.z.string() })
      })
    ]).nullish()
  }).nullish(),

AI SDK Version

  • ai: 5.0.59
  • ai-sdk/amazon-bedrock: 3.0.29

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` label
    provider/amazon-bedrockIssues related to the @ai-sdk/amazon-bedrock provider
    and removed on Oct 15, 2025
  2. hendychua commented on Feb 24, 2026

    @hendychua

    Hi, facing this issue too. Any updates or workarounds for now? Thank you.

  3. lgrammel commented on Jul 2, 2026

    @lgrammel
    Collaborator

    Identify issue type

    {
      "evidence": [
        "Streaming Bedrock with `citations: { enabled: true }` fails with `AI_TypeValidationError` in `BedrockStreamSchema`.",
        "The reported Bedrock response contains a valid `delta.citation`, but the schema union only accepts text, toolUse, or reasoningContent variants.",
        "A commenter confirms they are facing the same issue and asks for workarounds."
      ],
      "rationale": "The issue describes current Amazon Bedrock streaming behavior throwing a validation error for valid citation deltas when citations are enabled, which is a concrete failure in existing SDK behavior.",
      "type": "bug",
      "confidence": "high"
    }
  4. added theissue type on Jul 2, 2026
  5. ai-sdk-factory commented on Jul 31, 2026

    @ai-sdk-factory
    Contributor

    Bug Reproduction

    Bug was reproduced.

    Branch: main
    PR: successful reproduction pull request

    Details

    • Live Bedrock streaming with citations.enabled: true returned documented citation deltas, but AI SDK emitted AI_TypeValidationError instead of accepting them.
    • packages/amazon-bedrock/src/amazon-bedrock-chat-language-model.ts still omits citation from AmazonBedrockStreamSchema on current main (@ai-sdk/amazon-bedrock 5.0.38), so upgrading from the reported versions does not resolve the issue.
    • packages/amazon-bedrock/src/__fixtures__/amazon-bedrock-document-citations.chunks.txt records the live provider response containing six citation deltas.
    • packages/amazon-bedrock/src/amazon-bedrock-chat-language-model-citations.test.ts expected zero citation validation errors but observed six when replaying the live fixture.
    • examples/ai-functions/src/reproduction/issue-9101-bedrock-stream-citations.ts expected citation-enabled streaming without validation errors but observed the reported failure against the live provider.

    Relevant Documentation

  6. ai-sdk-factory commented on Jul 31, 2026

    @ai-sdk-factory
    Contributor

    Bugfix

    Created bugfix and opened PR: #18250

    Root Cause

    AmazonBedrockStreamSchema omitted citation from its contentBlockDelta union. The live reproduction produced six citation validation errors, and the focused schema-validation regression test failed before the schema change.

    Summary

    Added citation objects to the Bedrock stream schema, added regression coverage, removed reproduction-only artifacts, and added a patch changeset for @ai-sdk/amazon-bedrock.

    Testing

    Added a streaming regression test that validates a representative citation delta through AmazonBedrockStreamSchema and asserts that no error part is emitted.

  7. 5 remaining items

  8. added a commit that references this issue on Aug 27, 2026
    b2eb608
  9. ai-sdk-factory commented on Aug 27, 2026

    @ai-sdk-factory
    Contributor

    Backport to v5.0

    created: #19891 (fixed merge).

  10. ai-sdk-factory commented on Aug 27, 2026

    @ai-sdk-factory
    Contributor

    Backport to v6.0

    created: #19892 (fixed merge).

  11. added 2 commits that reference this issue on Aug 27, 2026
    6b88988
    0393692
  12. github-actions commented on Aug 28, 2026

    @github-actions
    Contributor

    🚀 Published in:

    Package Version
    ai 7.0.84 github npm
    @ai-sdk/alibaba 2.0.38 github npm
    @ai-sdk/amazon-bedrock 5.0.67 github npm
    @ai-sdk/angular 3.0.84 github npm
    @ai-sdk/anthropic 4.0.45 github npm
    @ai-sdk/anthropic-aws 2.0.37 github npm
    @ai-sdk/assemblyai 3.0.33 github npm
    @ai-sdk/azure 4.0.53 github npm
    @ai-sdk/baseten 2.1.18 github npm
    @ai-sdk/black-forest-labs 2.0.34 github npm
    @ai-sdk/bytedance 2.0.36 github npm
    @ai-sdk/cartesia 3.0.28 github npm
    @ai-sdk/cerebras 3.0.40 github npm
    @ai-sdk/code-mode 1.0.41 github npm
    @ai-sdk/cohere 4.0.34 github npm
    @ai-sdk/deepgram 3.1.4 github npm
    @ai-sdk/deepinfra 3.0.40 github npm
    @ai-sdk/deepseek 3.0.36 github npm
    @ai-sdk/elevenlabs 3.0.34 github npm
    @ai-sdk/fal 3.0.34 github npm
    @ai-sdk/fireworks 3.0.43 github npm
    @ai-sdk/fish-audio 3.0.11 github npm
    @ai-sdk/gateway 4.0.68 github npm
    @ai-sdk/gladia 3.0.33 github npm
    @ai-sdk/gmicloud 3.0.11 github npm
    @ai-sdk/google 4.0.57 github npm
    @ai-sdk/google-vertex 5.0.69 github npm
    @ai-sdk/groq 4.0.34 github npm
    @ai-sdk/harness 1.0.93 github npm
    @ai-sdk/harness-acp 1.0.31 github npm
    @ai-sdk/harness-claude-code 1.0.97 github npm
    @ai-sdk/harness-cline 1.0.20 github npm
    @ai-sdk/harness-codex 1.0.95 github npm
    @ai-sdk/harness-cursor 1.0.6 github npm
    @ai-sdk/harness-deepagents 1.0.93 github npm
    @ai-sdk/harness-fx 1.0.6 github npm
    @ai-sdk/harness-grok-build 1.0.30 github npm
    @ai-sdk/harness-opencode 1.0.95 github npm
    @ai-sdk/harness-pi 1.0.95 github npm
    @ai-sdk/huggingface 2.0.40 github npm
    @ai-sdk/hume 3.0.33 github npm
    @ai-sdk/klingai 4.0.35 github npm
    @ai-sdk/langchain 3.0.84 github npm
    @ai-sdk/llamaindex 3.0.84 github npm
    @ai-sdk/lmnt 3.0.33 github npm
    @ai-sdk/luma 3.0.34 github npm
    @ai-sdk/mcp 2.0.40 github npm
    @ai-sdk/minimax 3.0.21 github npm
    @ai-sdk/mistral 4.0.36 github npm
    @ai-sdk/moonshotai 3.0.42 github npm
    @ai-sdk/open-responses 2.0.35 github npm
    @ai-sdk/openai 4.0.51 github npm
    @ai-sdk/openai-compatible 3.0.40 github npm
    @ai-sdk/otel 1.0.84 github npm
    @ai-sdk/perplexity 4.0.35 github npm
    @ai-sdk/policy-opa 1.0.84 github npm
    @ai-sdk/prodia 2.0.34 github npm
    @ai-sdk/provider-utils 5.0.33 github npm
    @ai-sdk/quiverai 2.0.33 github npm
    @ai-sdk/react 4.0.87 github npm
    @ai-sdk/replicate 3.0.34 github npm
    @ai-sdk/revai 3.0.33 github npm
    @ai-sdk/rsc 3.0.84 github npm
    @ai-sdk/sandbox-just-bash 1.0.93 github npm
    @ai-sdk/sandbox-vercel 1.0.93 github npm
    @ai-sdk/svelte 5.0.84 github npm
    @ai-sdk/togetherai 3.0.41 github npm
    @ai-sdk/tui 1.0.85 github npm
    @ai-sdk/valibot 3.0.33 github npm
    @ai-sdk/voyage 2.0.33 github npm
    @ai-sdk/vue 4.0.84 github npm
    @ai-sdk/workflow 2.0.14 github npm
    @ai-sdk/workflow-harness 1.0.93 github npm
    @ai-sdk/xai 4.0.49 github npm
    @ai-sdk/zai 3.0.2 github npm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions