Skip to content

fix(langchain): keep content blocks of JS input messages on spans - #3820

Open
Harsh23Kashyap wants to merge 1 commit into
Arize-ai:mainfrom
Harsh23Kashyap:fix/js-langchain-content-blocks
Open

Harsh23Kashyap wants to merge 1 commit into
Arize-ai:mainfrom
Harsh23Kashyap:fix/js-langchain-content-blocks

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown

Fixes #3819

In the JS langchain instrumentors, a message whose content is an array of content blocks reaches the span with only its role. Multimodal messages, tool_result blocks, and any other structured content record as an empty message, because getContentFromMessageData keeps string content and discards everything else.

This change records each content block as a message.contents.N entry, in both openinference-instrumentation-langchain and openinference-instrumentation-langchain-v0, which share the same parsing helper:

  • text blocks carry message_content.type = "text" and their text; plain strings inside the array count as text.
  • image_url blocks carry message_content.type = "image" and their url, whether the value is a string or an object.
  • Unknown block types are skipped, matching the python langchain tracer this mirrors.
  • String content, roles, tool calls, and function calls are unchanged.

Test plan:

  • New regression test should record content blocks as message contents in test/utils.test.ts of both packages; fails on main and passes with this change.
  • pnpm vitest run - 83 passed (langchain), 81 passed (langchain-v0), existing suites unaffected.

This branch has not been deployed

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

langchain (JS): input messages with content blocks are recorded without any content

1 participant