{"record":{"id":"979f988729ff6c65","repo":"langchain-ai/langchain","slug":"unrecognized-content-block-at-messages-i-conten-979f98","errorCode":null,"errorMessage":"Unrecognized content block at messages[{i}].content[{j}] has 'type': 'image' but 'source' is missing expected key(s) {missing}. Full content block:\n\n{block}","messagePattern":"Unrecognized content block at messages\\[(.+?)\\]\\.content\\[(.+?)\\] has 'type': 'image' but 'source' is missing expected key\\(s\\) (.+?)\\. Full content block:\n\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/messages/utils.py","lineNumber":1738,"sourceCode":"                        and \"filename\" not in formatted_block[\"file\"]\n                    ):\n                        logger.info(\"Generating a fallback filename.\")\n                        formatted_block[\"file\"][\"filename\"] = \"LC_AUTOGENERATED\"\n                    content.append(formatted_block)\n                # Anthropic and Bedrock converse format\n                elif (block.get(\"type\") == \"image\") or \"image\" in block:\n                    # Anthropic\n                    if source := block.get(\"source\"):\n                        if missing := [\n                            k for k in (\"media_type\", \"type\", \"data\") if k not in source\n                        ]:\n                            err = (\n                                f\"Unrecognized content block at \"\n                                f\"messages[{i}].content[{j}] has 'type': 'image' \"\n                                f\"but 'source' is missing expected key(s) \"\n                                f\"{missing}. Full content block:\\n\\n{block}\"\n                            )\n                            raise ValueError(err)\n                        content.append(\n                            {\n                                \"type\": \"image_url\",\n                                \"image_url\": {\n                                    \"url\": (\n                                        f\"data:{source['media_type']};\"\n                                        f\"{source['type']},{source['data']}\"\n                                    )\n                                },\n                            }\n                        )\n                    # Bedrock converse\n                    elif image := block.get(\"image\"):\n                        if missing := [\n                            k for k in (\"source\", \"format\") if k not in image\n                        ]:\n                            err = (\n                                f\"Unrecognized content block at \"","sourceCodeStart":1720,"sourceCodeEnd":1756,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/messages/utils.py#L1720-L1756","documentation":"Raised by `convert_to_openai_messages` when converting an Anthropic-style image block (`{'type': 'image', 'source': {...}}`): the `source` dict must contain 'media_type', 'type', and 'data' so the converter can assemble a `data:<media_type>;<type>,<data>` URL. Missing any of those keys triggers this error with the full block printed.","triggerScenarios":"An Anthropic image block whose source is incomplete, e.g. `{'type': 'image', 'source': {'type': 'base64', 'data': '...'}}` without 'media_type', or a source that is a URL string instead of the expected dict shape.","commonSituations":"Relaying raw Anthropic API payloads into langchain message content; stripping fields during JSON transport; hand-building blocks from memory of the Anthropic schema.","solutions":["Provide all three source keys: `{'type': 'base64', 'media_type': 'image/png', 'data': '<base64>'}`","If you only have a URL, use the OpenAI shape `{'type': 'image_url', 'image_url': {'url': ...}}` instead","Validate source dict keys before assembling Anthropic blocks"],"exampleFix":"# before\n{'type': 'image', 'source': {'type': 'base64', 'data': b64}}\n\n# after\n{'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/png', 'data': b64}}","handlingStrategy":"validation","validationCode":"def valid_anthropic_source(s) -> bool:\n    return (isinstance(s, dict)\n            and all(k in s for k in ('media_type', 'type', 'data'))\n            and isinstance(s.get('data'), str))","typeGuard":"def is_wellformed_anthropic_image(b: object) -> bool:\n    return (isinstance(b, dict) and b.get('type') == 'image'\n            and isinstance(b.get('source'), dict)\n            and all(k in b['source'] for k in ('media_type', 'type', 'data')))","tryCatchPattern":null,"preventionTips":["Include media_type, type, and data in every Anthropic image source dict","If you only hold a URL, emit the OpenAI image_url shape instead of an Anthropic block","Validate relayed Anthropic payloads before embedding them in message content"],"tags":["anthropic","openai","content-blocks","multimodal","images"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}