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

Type Contract Violations In Import_attr And Content_blocks Allow Invalid Values And Return Types

langchain-core 1.6.6 contains two type contract inconsistencies: import_attr accepts package=None but raises TypeError due to always using relative imports, and AIMessage/AIMessageChunk.content_blocks return list[str] when content is a list of strings, violating the declared return type list[ContentBlock].

highConfidence 92%Langchain-CoreAgentslangchain-coreAffected V1.6.6

Origin Analysis

1) import_attr always calls importlib.import_module(f'.{module_name}', package), which requires a non-None package; the type hint package: str | None allows None, leading to TypeError. 2) The content_blocks property only converts string content to a list of text blocks but does not normalize individual string elements inside a list, returning the raw list of strings despite the type annotation.
1) Run import_attr('x', 'y', None) with langchain_core imported; observe TypeError: the 'package' argument is required to perform a relative import. 2) Create AIMessage or AIMessageChunk with content=['hello'] and response_metadata={'output_version': 'v1'}; print message.content_blocks; observe ['hello'] (list of str) instead of list of dict blocks.

Fixing Code Block

Edge Case Audit

Changing import_attr may alter behavior for callers that passed package=None expecting TypeError; now they will trigger absolute imports, which could import an unintended module if module_name is not fully qualified. Changing content_blocks will modify return type for list[str] inputs: previously list[str], now list[dict]; any downstream code that assumes list[str] elements will break. Dict elements are not validated against the ContentBlock TypedDict, so malformed dicts could still violate the type hint. Rollback: revert to original property or pin langchain-core==1.6.6. Test with integrations that consume content_blocks (e.g., Anthropic, OpenAI tool calling) before deploying.

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