{"record":{"id":"b0a36737be17dc69","repo":"langchain-ai/langchain","slug":"unrecognized-content-block-at-messages-i-conten-b0a367","errorCode":null,"errorMessage":"Unrecognized content block at messages[{i}].content[{j}] does not match OpenAI, Anthropic, Bedrock Converse, or VertexAI format. Full content block:\n\n{block}","messagePattern":"Unrecognized content block at messages\\[(.+?)\\]\\.content\\[(.+?)\\] does not match OpenAI, Anthropic, Bedrock Converse, or VertexAI format\\. Full content block:\n\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/messages/utils.py","lineNumber":1954,"sourceCode":"                            \"type\": \"image_url\",\n                            \"image_url\": {\n                                \"url\": (f\"data:{block['mime_type']};base64,{b64_image}\")\n                            },\n                        }\n                    )\n                elif (\n                    block.get(\"type\") in {\"thinking\", \"reasoning\"}\n                    or pass_through_unknown_blocks\n                ):\n                    content.append(block)\n                else:\n                    err = (\n                        f\"Unrecognized content block at \"\n                        f\"messages[{i}].content[{j}] does not match OpenAI, \"\n                        f\"Anthropic, Bedrock Converse, or VertexAI format. Full \"\n                        f\"content block:\\n\\n{block}\"\n                    )\n                    raise ValueError(err)\n            if text_format == \"string\" and not any(\n                block[\"type\"] != \"text\" for block in content\n            ):\n                content = \"\\n\".join(block[\"text\"] for block in content)\n        oai_msg[\"content\"] = content\n        if message.content and not oai_msg[\"content\"] and tool_messages:\n            oai_messages.extend(tool_messages)\n        else:\n            oai_messages.extend([oai_msg, *tool_messages])\n\n    if is_single:\n        return oai_messages[0]\n    return oai_messages\n\n\ndef _first_max_tokens(\n    messages: Sequence[BaseMessage],\n    *,","sourceCodeStart":1936,"sourceCodeEnd":1972,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/messages/utils.py#L1936-L1972","documentation":"This is the terminal `else` of the content-block dispatch in `convert_to_openai_messages`: the block matched none of the recognized dialects (OpenAI text/image_url/file, Anthropic, Bedrock Converse, tool_use/tool_result, json, guard_content, media) and is not a `thinking`/`reasoning` block. Rather than silently dropping or forwarding unknown data to the OpenAI API, the converter raises. If the flag `pass_through_unknown_blocks=True` was set, unknown blocks would instead be passed through — the fact you see this error means that flag was not enabled (or the block fell in a branch that does not honor it).","triggerScenarios":"Typos in the type tag (`\"txt\"`, `\"Image\"`, `\"image-url\"`); proprietary block types from other frameworks (e.g. Cohere/Gemini-specific shapes); blocks that are plain strings where dicts are expected can also fall through depending on surrounding handling.","commonSituations":"Feeding raw provider responses from unsupported providers into the converter; schema drift after a partner package update introduced new block types; copy-paste of example payloads with subtle type-name errors.","solutions":["Check the echoed `block` in the error: fix the `type` tag to a supported value (`text`, `image_url`, `image`, `tool_use`, `tool_result`, `json`, `guard_content`, `media`, `file`).","If the block is legitimately non-standard and your target tolerates it, pass `pass_through_unknown_blocks=True` to `convert_to_openai_messages`.","Map custom block types to `text` blocks (`{\"type\": \"text\", \"text\": json.dumps(block)}`) before conversion.","Reasoning blocks must use `thinking` or `reasoning` as the type to be passed through."],"exampleFix":"// before\nconvert_to_openai_messages([HumanMessage(content=[{\"type\": \"txt\", \"txt\": \"hi\"}])])\n\n// after\nconvert_to_openai_messages([HumanMessage(content=[{\"type\": \"text\", \"text\": \"hi\"}])])","handlingStrategy":"validation","validationCode":"KNOWN_TYPES = {\"text\", \"image_url\", \"image\", \"file\", \"tool_use\", \"tool_result\", \"json\", \"guard_content\", \"media\", \"thinking\", \"reasoning\"}\n\ndef unrecognized(block) -> bool:\n    return isinstance(block, dict) and block.get(\"type\") not in KNOWN_TYPES\n\nbad = [b for b in blocks if unrecognized(b)]\nif bad:\n    raise ValueError(f\"unsupported blocks: {bad}\")","typeGuard":"def is_known_content_block(b: dict) -> bool:\n    return b.get(\"type\") in {\"text\", \"image_url\", \"image\", \"file\", \"tool_use\", \"tool_result\", \"json\", \"guard_content\", \"media\", \"thinking\", \"reasoning\"}","tryCatchPattern":"try:\n    oai = convert_to_openai_messages(messages)\nexcept ValueError:\n    # opt into passthrough if the target provider tolerates the block\n    oai = convert_to_openai_messages(messages, pass_through_unknown_blocks=True)","preventionTips":["Validate provider payloads at the trust boundary before they enter LangChain","Check the type tag spelling against the supported set in one shared constant","Convert proprietary blocks to text blocks (json.dumps) as a universal fallback"],"tags":["messages","content-blocks","openai-conversion","unsupported-format","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}