AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Content Block Corruption When Using Type File

Accessing message.content_blocks inside a chat model start callback raises TypeError because the legacy v0 file block conversion passes the block's 'id' both explicitly and via **extras to create_file_block.

highConfidence 95%Langchain-CoreAffected V1.4.6

Origin Analysis

In langchain_core.messages.block_translators.langchain_v0._convert_legacy_v0_content_block_to_v1, the file block branch builds an extras dictionary that contains the 'id' key while simultaneously passing id explicitly to create_file_block. This causes Python to raise 'got multiple values for keyword argument "id"'.
Instantiate ChatOpenAI with a custom AsyncCallbackHandler that accesses message.content_blocks in on_chat_model_start. Send a HumanMessage built with create_file_block. The callback triggers conversion of legacy v0 file blocks, hitting the duplicate id argument and raising TypeError.

Fixing Code Block

Edge Case Audit

The fix preserves id by passing it explicitly and filtering it from extras. Ensure that any downstream code that expected id to be only in **extras is unaffected. The function is stateless, so concurrency is safe, but other legacy v0 block types may have similar duplicate id patterns and should be audited. Rollback: revert this function to the original implementation if callback regressions or unexpected id handling are observed.

Ecosystem Topology