Home / Function/ _is_code_execution_related_block() — langchain Function Reference

_is_code_execution_related_block() — langchain Function Reference

Architecture documentation for the _is_code_execution_related_block() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2e7e015c_db4c_1a62_b5dd_3a0aac0d665c["_is_code_execution_related_block()"]
  a85819c7_917d_4c71_2864_a19e68947340["chat_models.py"]
  2e7e015c_db4c_1a62_b5dd_3a0aac0d665c -->|defined in| a85819c7_917d_4c71_2864_a19e68947340
  954f0cfe_731b_ac1b_0145_b5a3d210030b["_get_request_payload()"]
  954f0cfe_731b_ac1b_0145_b5a3d210030b -->|calls| 2e7e015c_db4c_1a62_b5dd_3a0aac0d665c
  style 2e7e015c_db4c_1a62_b5dd_3a0aac0d665c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/chat_models.py lines 694–721

def _is_code_execution_related_block(
    block: dict,
    code_execution_tool_ids: set[str],
) -> bool:
    """Check if a content block is related to code_execution.

    Returns True for blocks that should NOT have cache_control applied.
    """
    if not isinstance(block, dict):
        return False

    block_type = block.get("type")

    # tool_use blocks called by code_execution
    if block_type == "tool_use":
        caller = block.get("caller")
        if isinstance(caller, dict):
            caller_type = caller.get("type", "")
            if caller_type.startswith("code_execution"):
                return True

    # tool_result blocks for code_execution called tools
    if block_type == "tool_result":
        tool_use_id = block.get("tool_use_id")
        if tool_use_id and tool_use_id in code_execution_tool_ids:
            return True

    return False

Domain

Subdomains

Frequently Asked Questions

What does _is_code_execution_related_block() do?
_is_code_execution_related_block() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/chat_models.py.
Where is _is_code_execution_related_block() defined?
_is_code_execution_related_block() is defined in libs/partners/anthropic/langchain_anthropic/chat_models.py at line 694.
What calls _is_code_execution_related_block()?
_is_code_execution_related_block() is called by 1 function(s): _get_request_payload.

Analyze Your Own Codebase

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

Try Supermodel Free