Home / Function/ create_plaintext_block() — langchain Function Reference

create_plaintext_block() — langchain Function Reference

Architecture documentation for the create_plaintext_block() function in content.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  23986307_22ae_2123_de50_d0f1db2e9850["create_plaintext_block()"]
  c7f11daf_e104_efbe_7225_f1d6da8e8630["content.py"]
  23986307_22ae_2123_de50_d0f1db2e9850 -->|defined in| c7f11daf_e104_efbe_7225_f1d6da8e8630
  style 23986307_22ae_2123_de50_d0f1db2e9850 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/content.py lines 1255–1315

def create_plaintext_block(
    text: str | None = None,
    url: str | None = None,
    base64: str | None = None,
    file_id: str | None = None,
    title: str | None = None,
    context: str | None = None,
    id: str | None = None,
    index: int | str | None = None,
    **kwargs: Any,
) -> PlainTextContentBlock:
    """Create a `PlainTextContentBlock`.

    Args:
        text: The plaintext content.
        url: URL of the plaintext file.
        base64: Base64-encoded plaintext data.
        file_id: ID of the plaintext file from a file storage system.
        title: Title of the text data.
        context: Context or description of the text content.
        id: Content block identifier.

            Generated automatically if not provided.
        index: Index of block in aggregate response.

            Used during streaming.

    Returns:
        A properly formatted `PlainTextContentBlock`.

    !!! note

        The `id` is generated automatically if not provided, using a UUID4 format
        prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
    """
    block = PlainTextContentBlock(
        type="text-plain",
        mime_type="text/plain",
        id=ensure_id(id),
    )

    if text is not None:
        block["text"] = text
    if url is not None:
        block["url"] = url
    if base64 is not None:
        block["base64"] = base64
    if file_id is not None:
        block["file_id"] = file_id
    if title is not None:
        block["title"] = title
    if context is not None:
        block["context"] = context
    if index is not None:
        block["index"] = index

    extras = {k: v for k, v in kwargs.items() if v is not None}
    if extras:
        block["extras"] = extras

    return block

Domain

Subdomains

Frequently Asked Questions

What does create_plaintext_block() do?
create_plaintext_block() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/content.py.
Where is create_plaintext_block() defined?
create_plaintext_block() is defined in libs/core/langchain_core/messages/content.py at line 1255.

Analyze Your Own Codebase

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

Try Supermodel Free