Home / Function/ _ensure_message_copy() — langchain Function Reference

_ensure_message_copy() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/langchain_core/language_models/_utils.py lines 295–301

def _ensure_message_copy(message: T, formatted_message: T) -> T:
    """Create a copy of the message if it hasn't been copied yet."""
    if formatted_message is message:
        formatted_message = message.model_copy()
        # Shallow-copy content list to allow modifications
        formatted_message.content = list(formatted_message.content)
    return formatted_message

Subdomains

Frequently Asked Questions

What does _ensure_message_copy() do?
_ensure_message_copy() is a function in the langchain codebase, defined in libs/core/langchain_core/language_models/_utils.py.
Where is _ensure_message_copy() defined?
_ensure_message_copy() is defined in libs/core/langchain_core/language_models/_utils.py at line 295.
What calls _ensure_message_copy()?
_ensure_message_copy() 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