LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coremessagesbaseBaseMessage
    Class●Since v0.1

    BaseMessage

    Base abstract message class.

    Messages are the inputs and outputs of a chat model.

    Examples include HumanMessage, AIMessage, and SystemMessage.

    Copy
    BaseMessage(
      self,
      content: str | list[str | dict] | None = None,
      content_blocks: list[types.ContentBlock] | None = None,
      **kwargs: Any = {}
    )

    Bases

    Serializable

    Used in Docs

    • Frontend
    • MESSAGE_COERCION_FAILURE
    • Quickstart
    • Use the functional API
    • Workflows and agents

    Parameters

    NameTypeDescription
    contentstr | list[str | dict] | None
    Default:None

    The contents of the message.

    content_blockslist[types.ContentBlock] | None
    Default:None

    Typed standard content.

    **kwargsAny
    Default:{}

    Additional arguments to pass to the parent class.

    Constructors

    constructor
    __init__
    NameType
    contentstr | list[str | dict] | None
    content_blockslist[types.ContentBlock] | None

    Attributes

    attribute
    content: str | list[str | dict]

    The contents of the message.

    attribute
    additional_kwargs: dict

    Reserved for additional payload data associated with the message.

    For example, for a message from an AI, this could include tool calls as encoded by the model provider.

    attribute
    response_metadata: dict

    Examples: response headers, logprobs, token counts, model name.

    attribute
    type: str

    The type of the message. Must be a string that is unique to the message type.

    The purpose of this field is to allow for easy identification of the message type when deserializing messages.

    attribute
    name: str | None

    An optional name for the message.

    This can be used to provide a human-readable name for the message.

    Usage of this field is optional, and whether it's used or not is up to the model implementation.

    attribute
    id: str | None

    An optional unique identifier for the message.

    This should ideally be provided by the provider/model which created the message.

    attribute
    model_config
    attribute
    content_blocks: list[types.ContentBlock]

    Load content blocks from the message content.

    attribute
    text: TextAccessor

    Get the text content of the message as a string.

    Can be used as both property (message.text) and method (message.text()).

    Handles both string and list content types (e.g. for content blocks). Only extracts blocks with type: 'text'; other block types are ignored.

    Deprecated

    As of langchain-core 1.0.0, calling .text() as a method is deprecated. Use .text as a property instead. This method will be removed in 2.0.0.

    Methods

    method
    is_lc_serializable

    BaseMessage is serializable.

    method
    get_lc_namespace

    Get the namespace of the LangChain object.

    method
    pretty_repr

    Get a pretty representation of the message.

    method
    pretty_print

    Print a pretty representation of the message.

    Inherited fromSerializable

    Attributes

    Alc_secrets: dict[str, str]
    —

    A map of constructor argument names to secret ids.

    Alc_attributes: dict
    —

    List of attribute names that should be included in the serialized kwargs.

    Methods

    Mlc_id
    —

    Return a unique identifier for this class for serialization purposes.

    Mto_json
    —

    Convert the graph to a JSON-serializable format.

    Mto_json_not_implemented
    —

    Serialize a "not implemented" object.

    View source on GitHub