Home / Class/ PlainTextContentBlock Class — langchain Architecture

PlainTextContentBlock Class — langchain Architecture

Architecture documentation for the PlainTextContentBlock class in content.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8910cc6d_8823_a915_cc61_5db603e42191["PlainTextContentBlock"]
  c7f11daf_e104_efbe_7225_f1d6da8e8630["content.py"]
  8910cc6d_8823_a915_cc61_5db603e42191 -->|defined in| c7f11daf_e104_efbe_7225_f1d6da8e8630

Relationship Graph

Source Code

libs/core/langchain_core/messages/content.py lines 651–718

class PlainTextContentBlock(TypedDict):
    """Plaintext data (e.g., from a `.txt` or `.md` document).

    !!! note

        A `PlainTextContentBlock` existed in `langchain-core<1.0.0`. Although the
        name has carried over, the structure has changed significantly. The only shared
        keys between the old and new versions are `type` and `text`, though the
        `type` value has changed from `'text'` to `'text-plain'`.

    !!! note

        Title and context are optional fields that may be passed to the model. See
        Anthropic [example](https://platform.claude.com/docs/en/build-with-claude/citations#citable-vs-non-citable-content).

    !!! note "Factory function"

        `create_plaintext_block` may also be used as a factory to create a
        `PlainTextContentBlock`. Benefits include:

        * Automatic ID generation (when not provided)
        * Required arguments strictly validated at creation time
    """

    type: Literal["text-plain"]
    """Type of the content block. Used for discrimination."""

    id: NotRequired[str]
    """Unique identifier for this content block.

    Either:

    - Generated by the provider
    - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
    """

    file_id: NotRequired[str]
    """Reference to the plaintext file in an external file storage system.

    For example, OpenAI or Anthropic's Files API.
    """

    mime_type: Literal["text/plain"]
    """MIME type of the file.

    Required for base64 data.
    """

    index: NotRequired[int | str]
    """Index of block in aggregate response. Used during streaming."""

    url: NotRequired[str]
    """URL of the plaintext."""

    base64: NotRequired[str]
    """Data as a base64 string."""

    text: NotRequired[str]
    """Plaintext content. This is optional if the data is provided as base64."""

    title: NotRequired[str]
    """Title of the text data, e.g., the title of a document."""

    context: NotRequired[str]
    """Context for the text, e.g., a description or summary of the text's content."""

    extras: NotRequired[dict[str, Any]]
    """Provider-specific metadata. This shouldn't be used for the data itself."""

Frequently Asked Questions

What is the PlainTextContentBlock class?
PlainTextContentBlock is a class in the langchain codebase, defined in libs/core/langchain_core/messages/content.py.
Where is PlainTextContentBlock defined?
PlainTextContentBlock is defined in libs/core/langchain_core/messages/content.py at line 651.

Analyze Your Own Codebase

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

Try Supermodel Free