Home / File/ parsed_message.py — anthropic-sdk-python Source File

parsed_message.py — anthropic-sdk-python Source File

Architecture documentation for parsed_message.py, a python file in the anthropic-sdk-python codebase. 17 imports, 1 dependents.

File python AnthropicClient SyncAPI 17 imports 1 dependents 2 classes

Entity Profile

Dependency Diagram

graph LR
  3c1d116b_af29_e9f2_495b_ceebd1febd18["parsed_message.py"]
  b20bf822_b103_aa1e_5714_0992f46c51e4["_utils"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> b20bf822_b103_aa1e_5714_0992f46c51e4
  21a395d8_015e_6c08_b7bd_94e93c67aaf8["message.py"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 21a395d8_015e_6c08_b7bd_94e93c67aaf8
  01beb2f6_442c_779e_7c57_22078b50dcf4["Message"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 01beb2f6_442c_779e_7c57_22078b50dcf4
  7011abba_fb52_65c0_a717_c6c8750f4696["text_block.py"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 7011abba_fb52_65c0_a717_c6c8750f4696
  7af6ce9f_6b89_6438_fd73_c9fc07a7ba28["TextBlock"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 7af6ce9f_6b89_6438_fd73_c9fc07a7ba28
  56e50d54_5b4d_82e3_ece3_b2c06bab9ba1["thinking_block.py"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 56e50d54_5b4d_82e3_ece3_b2c06bab9ba1
  535c05f0_8001_833b_d340_a6d302a962d2["ThinkingBlock"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 535c05f0_8001_833b_d340_a6d302a962d2
  e3429280_22da_46a4_ce98_8cc1a41b5e09["tool_use_block.py"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> e3429280_22da_46a4_ce98_8cc1a41b5e09
  c99fded7_4bd3_789e_0b8b_6389fef4f668["ToolUseBlock"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> c99fded7_4bd3_789e_0b8b_6389fef4f668
  78627741_c7b7_07ee_0934_4ebc83a09460["server_tool_use_block.py"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 78627741_c7b7_07ee_0934_4ebc83a09460
  ef50e7f8_c97f_3caa_daef_59a0a478750b["ServerToolUseBlock"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> ef50e7f8_c97f_3caa_daef_59a0a478750b
  2eda2717_3fea_6ae9_cb24_99f550df61b9["redacted_thinking_block.py"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 2eda2717_3fea_6ae9_cb24_99f550df61b9
  3ffbde90_346e_f63e_1e2c_b8c65b9c4566["RedactedThinkingBlock"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 3ffbde90_346e_f63e_1e2c_b8c65b9c4566
  7211cd22_539d_da2a_2925_b19c682fb82e["web_search_tool_result_block.py"]
  3c1d116b_af29_e9f2_495b_ceebd1febd18 --> 7211cd22_539d_da2a_2925_b19c682fb82e
  style 3c1d116b_af29_e9f2_495b_ceebd1febd18 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from typing import TYPE_CHECKING, List, Union, Generic, Optional
from typing_extensions import TypeVar, Annotated, TypeAlias

from .._utils import PropertyInfo
from .message import Message
from .text_block import TextBlock
from .thinking_block import ThinkingBlock
from .tool_use_block import ToolUseBlock
from .server_tool_use_block import ServerToolUseBlock
from .redacted_thinking_block import RedactedThinkingBlock
from .web_search_tool_result_block import WebSearchToolResultBlock

ResponseFormatT = TypeVar("ResponseFormatT", default=None)


__all__ = [
    "ParsedTextBlock",
    "ParsedContentBlock",
    "ParsedMessage",
]


class ParsedTextBlock(TextBlock, Generic[ResponseFormatT]):
    parsed_output: Optional[ResponseFormatT] = None

    __api_exclude__ = {"parsed_output"}


# Note that generic unions are not valid for pydantic at runtime
ParsedContentBlock: TypeAlias = Annotated[
    Union[
        ParsedTextBlock[ResponseFormatT],
        ThinkingBlock,
        RedactedThinkingBlock,
        ToolUseBlock,
        ServerToolUseBlock,
        WebSearchToolResultBlock,
    ],
    PropertyInfo(discriminator="type"),
]


class ParsedMessage(Message, Generic[ResponseFormatT]):
    if TYPE_CHECKING:
        content: List[ParsedContentBlock[ResponseFormatT]]  # type: ignore[assignment]
    else:
        content: List[ParsedContentBlock]

    @property
    def parsed_output(self) -> Optional[ResponseFormatT]:
        for content in self.content:
            if content.type == "text" and content.parsed_output:
                return content.parsed_output
        return None

Subdomains

Frequently Asked Questions

What does parsed_message.py do?
parsed_message.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, SyncAPI subdomain.
What does parsed_message.py depend on?
parsed_message.py imports 17 module(s): Message, RedactedThinkingBlock, ServerToolUseBlock, TextBlock, ThinkingBlock, ToolUseBlock, WebSearchToolResultBlock, _utils, and 9 more.
What files import parsed_message.py?
parsed_message.py is imported by 1 file(s): __init__.py.
Where is parsed_message.py in the architecture?
parsed_message.py is located at src/anthropic/types/parsed_message.py (domain: AnthropicClient, subdomain: SyncAPI, directory: src/anthropic/types).

Analyze Your Own Codebase

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

Try Supermodel Free