Home / Function/ _update_content_block() — langchain Function Reference

_update_content_block() — langchain Function Reference

Architecture documentation for the _update_content_block() function in _utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4cfce0d8_9566_3400_9721_df2216aa19de["_update_content_block()"]
  52504dd3_f4d4_21a4_b28c_0c152227d20d["_utils.py"]
  4cfce0d8_9566_3400_9721_df2216aa19de -->|defined in| 52504dd3_f4d4_21a4_b28c_0c152227d20d
  030ac02c_2931_4d20_1689_430fac9b6609["_normalize_messages()"]
  030ac02c_2931_4d20_1689_430fac9b6609 -->|calls| 4cfce0d8_9566_3400_9721_df2216aa19de
  style 4cfce0d8_9566_3400_9721_df2216aa19de fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/language_models/_utils.py lines 304–315

def _update_content_block(
    formatted_message: "BaseMessage", idx: int, new_block: ContentBlock | dict
) -> None:
    """Update a content block at the given index, handling type issues."""
    # Type ignore needed because:
    # - `BaseMessage.content` is typed as `Union[str, list[Union[str, dict]]]`
    # - When content is str, indexing fails (index error)
    # - When content is list, the items are `Union[str, dict]` but we're assigning
    #   `Union[ContentBlock, dict]` where ContentBlock is richer than dict
    # - This is safe because we only call this when we've verified content is a list and
    #   we're doing content block conversions
    formatted_message.content[idx] = new_block  # type: ignore[index, assignment]

Subdomains

Frequently Asked Questions

What does _update_content_block() do?
_update_content_block() is a function in the langchain codebase, defined in libs/core/langchain_core/language_models/_utils.py.
Where is _update_content_block() defined?
_update_content_block() is defined in libs/core/langchain_core/language_models/_utils.py at line 304.
What calls _update_content_block()?
_update_content_block() is called by 1 function(s): _normalize_messages.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free