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

PlainTextContentBlock With Inline Text Is Rejected By Bedrock, Gemini And OpenAI Converters

langchain-core's create_plaintext_block(text=...) creates a 'text-plain' block carrying inline text, but the Bedrock, Gemini and OpenAI request converters ignore the inline text field and raise ValueError because they require url/base64/data/file_id. Anthropic already accepts the same block, causing inconsistent cross-provider behavior.

mediumConfidence 95%LangchainMemorylangchain-coreVector StoresAffected Vlangchain-Core==1.6.8Affected Vlangchain-Aws==1.8.1Affected Vlangchain-Google-Genai==4.4.0Affected Vlangchain-Openai==1.7.0

Origin Analysis

The provider-specific block translators treat every non-'text' content block as a data-only block. For type 'text-plain' they check only source fields such as 'url', 'base64', 'data' or 'file_id'. The standard PlainTextContentBlock supports an optional inline 'text' field, but the converters do not fall back to that field, so the block created by the library's own factory is rejected before sending.
1. Create a HumanMessage with content_blocks=[create_text_block('Summarise this.'), create_plaintext_block(text='hello world')].\n2. Call langchain_aws.chat_models.bedrock_converse._messages_to_bedrock([msg], None, provider='anthropic') -> ValueError unsupported data content block type 'text-plain'.\n3. Call ChatGoogleGenerativeAI(model='gemini-2.5-flash')._prepare_request(messages=[msg]) -> ValueError data block must contain url/base64/data.\n4. Call ChatOpenAI(model='gpt-4o')._get_request_payload([msg]) -> ValueError block of type text-plain is not supported.

Fixing Code Block

import langchain_aws.chat_models.bedrock_converse as bedrock_converse import langchain_google_genai.chat_models as genai_chat from langchain_core.messages.block_translators import openai as openai_translator # Bedrock: _format_data_content_block currently rejects text-plain _bedrock_original = bedrock_converse._format_data_content_block def _patched_bedrock_format(block): if ( block.get("type") == "text-plain" and block.get("text") is not None and not any(k in block for k in ("url", "base64", "data", "file_id")) ): return {"text": block["text"]} return _bedrock_original(block) bedrock_converse._format_data_content_block = _patched_bedrock_format # Gemini: preprocess text-plain inline text into a normal text part before original conversion _gemini_original_convert = genai_chat._convert_to_parts def _patched_gemini_convert(content, model=None): if isinstance(content, str): return _gemini_original_convert(content, model=model) converted = [] for block in content: if ( block.get("type") == "text-plain" and block.get("text") is not None and not any(k in block for k in ("url", "base64", "data", "file_id")) ): converted.append({"type": "text", "text": block["text"]}) else: converted.append(block) return _gemini_original_convert(converted, model=model) genai_chat._convert_to_parts = _patched_gemini_convert # OpenAI: make convert_to_openai_data_block return a text block when inline text is present _openai_original_convert = openai_translator.convert_to_openai_data_block def _patched_openai_convert(block, api=None): if ( block.get("type") == "text-plain" and block.get("text") is not None and not any(k in block for k in ("url", "base64", "data", "file_id")) ): return {"type": "text", "text": block["text"]} return _openai_original_convert(block, api=api) openai_translator.convert_to_openai_data_block = _patched_openai_convert
Each provider converter is patched to inspect inline text on a 'text-plain' block when no remote data source fields are present. Bedrock receives a native {'text': ...} part, Gemini receives a pre-converted {'type': 'text', 'text': ...} part, and OpenAI returns {'type': 'text', 'text': ...}. This aligns the three providers with the existing Anthropic behavior.

Edge Case Audit

This is a runtime monkey-patch hotfix; it should be removed after the official upstream fix is released. It accesses private functions whose signatures may change in future versions, causing import or call errors. The fallback deliberately ignores any unused source fields if inline text is present, which matches the expected behavior but may lose MIME/document semantics if a provider later supports richer text-plain handling. Rollback is possible by restoring the original function references saved in the patch or by not executing the patch. Test against the exact versions listed before production use.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state