Skip to content

[v6.0] fix: LangChain user image conversion returning provider-specific image_url blocks - #17692

Merged
lgrammel merged 2 commits into
release-v6.0from
backport-v6.0/11943-1
Jul 22, 2026
Merged

[v6.0] fix: LangChain user image conversion returning provider-specific image_url blocks#17692
lgrammel merged 2 commits into
release-v6.0from
backport-v6.0/11943-1

Conversation

@lgrammel

Copy link
Copy Markdown
Collaborator

Background

The published @ai-sdk/langchain adapter returned OpenAI-specific image_url blocks for URL and binary images instead of LangChain's canonical image blocks.

Root Cause

convertUserContent hard-coded OpenAI image serialization and constructed multimodal HumanMessages through content rather than contentBlocks. The reproduction confirmed inconsistent image output, and live ChatOpenAI validation showed canonical blocks require LangChain's v1 content marker for downstream translation.

Summary

Converted image inputs and image files to canonical LangChain image blocks and constructed multimodal messages through contentBlocks so LangChain marks and translates them as v1 content. Added a patch changeset.

Testing

Updated convertUserContent and convertModelMessages coverage for URL, binary, data-URL, and file-based images, including the v1 content marker.

End-to-end Validation

  • pnpm -C packages/langchain build && pnpm -C examples/ai-functions exec tsx -e <assertions> — built the package and confirmed canonical URL/binary image blocks while preserving canonical non-image files.
  • pnpm -C examples/next-langchain exec tsx -e <live ChatOpenAI validation> — GPT-4o accepted the converted JPEG and identified it as a blue-and-yellow macaw.

Related Issues

Fixes #11943

Closes #17619

Backport of #17629

Co-authored-by: jessieibarra 58125016+jessieibarra@users.noreply.github.com

@lgrammel

Copy link
Copy Markdown
Collaborator Author

Bugfix review

Outcome: approved

Fixes issue

Status: fully-addresses

URL, data-URL, base64, binary, and image-file inputs now produce canonical LangChain image blocks, and multimodal HumanMessages receive the v1 marker required for downstream provider translation.

Side effects

Risk: low

The intentional raw message representation change may affect consumers relying on the erroneous image_url shape, while text-only and non-image file behavior remains preserved.

Performance

Risk: none

Conversion remains single-pass and retains the existing base64 encoding approach without adding material allocations or repeated processing.

Backwards compatibility

Risk: low

Existing stored data is not migrated or mutated; only newly converted or persisted multimodal HumanMessages use canonical blocks and output_version v1 metadata.

Architecture

Risk: none

The private conversion helper remains owned by the LangChain adapter, consumes LangChain through its declared public messages export, and introduces no cross-package source imports or dependency inversion.

Change scope

Status: minimal

All four changed files are directly necessary: one localized implementation change, regression expectation updates at utility and adapter levels, and the required patch changeset.

Security

Risk: none

The change only restructures message data and performs no new fetching, execution, deserialization, credential handling, or trust-boundary crossing.

Testing

Status: appropriate

Regression coverage exercises URL, binary, base64, data-URL, URL-object, and image-file paths plus the v1 marker; focused checks also confirmed ArrayBuffer handling, non-image preservation, and OpenAI downstream translation.

Verification

Reviewed the complete merge-base diff and relevant LangChain types and provider converters. All 213 Node tests and 213 edge-runtime tests passed, as did package type checking, build, formatting, linting, diff validation, and focused canonical/downstream conversion assertions.

Relevant Documentation

@lgrammel
lgrammel merged commit 533f6c4 into release-v6.0 Jul 22, 2026
51 of 52 checks passed
@lgrammel
lgrammel deleted the backport-v6.0/11943-1 branch July 22, 2026 09:13
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 6.0.234 github npm
@ai-sdk/amazon-bedrock 4.0.139 github npm
@ai-sdk/angular 2.0.235 github npm
@ai-sdk/anthropic 3.0.100 github npm
@ai-sdk/anthropic-aws 1.0.22 github npm
@ai-sdk/azure 3.0.92 github npm
@ai-sdk/gateway 3.0.156 github npm
@ai-sdk/google 3.0.99 github npm
@ai-sdk/google-vertex 4.0.168 github npm
@ai-sdk/langchain 2.0.242 github npm
@ai-sdk/llamaindex 2.0.234 github npm
@ai-sdk/openai 3.0.87 github npm
@ai-sdk/react 3.0.236 github npm
@ai-sdk/rsc 2.0.234 github npm
@ai-sdk/svelte 4.0.234 github npm
@ai-sdk/vue 3.0.234 github npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant