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-coremessageshumanHumanMessage
    Class●Since v0.1

    HumanMessage

    Message from the user.

    A HumanMessage is a message that is passed in from a user to the model.

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

    Bases

    BaseMessage

    Example:

    from langchain_core.messages import HumanMessage, SystemMessage
    
    messages = [
        SystemMessage(content="You are a helpful assistant! Your name is Bob."),
        HumanMessage(content="What is your name?"),
    ]
    
    # Instantiate a chat model and invoke it with the messages
    model = ...
    print(model.invoke(messages))

    Used in Docs

    • Agents
    • Build a voice agent with LangChain
    • Build customer support with handoffs
    • Custom middleware
    • How to evaluate your agent with trajectory evaluations
    (86 more not shown)

    Constructors

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

    Attributes

    attribute
    type: Literal['human']

    The type of the message (used for serialization).

    Inherited fromBaseMessage

    Attributes

    Acontent: str | list[str | dict]
    —

    The contents of the message.

    Aadditional_kwargs: dict
    —

    Currently inherited from BaseMessage, but not used.

    Aresponse_metadata: dict
    —

    Currently inherited from BaseMessage, but not used.

    Aname: str
    —

    The name of the function.

    Aid: str
    —

    The unique identifier of the node.

    Amodel_configAcontent_blocks: list[types.ContentBlock]
    —

    Return standard, typed ContentBlock dicts from the message.

    Atext: str
    —

    Prompt text.

    Methods

    Mis_lc_serializable
    —

    Return True as this class is serializable.

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mpretty_repr
    —

    Return a pretty representation of the message for display.

    Mpretty_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.

    Amodel_config

    Methods

    Mis_lc_serializable
    —

    Return True as this class is serializable.

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    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