> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Messages

Messages are the fundamental unit of context for models in LangChain. They represent the input and output of models, carrying both the content and metadata needed to represent the state of a conversation when interacting with an LLM.

Messages are objects that contain:

* &#x20;[**Role**](#message-types) - Identifies the message type (e.g. `system`, `user`)
* &#x20;[**Content**](#message-content) - Represents the actual content of the message (like text, images, audio, documents, etc.)
* &#x20;[**Metadata**](#message-metadata) - Optional fields such as response information, message IDs, and token usage

LangChain provides a standard message type that works across all model providers, ensuring consistent behavior regardless of the model being called.

## Basic usage

The simplest way to use messages is to create message objects and pass them to a model when [invoking](https://docs.langchain.com/oss/python/langchain/models.md#invocation).

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.chat_models import init_chat_model
from langchain.messages import HumanMessage, AIMessage, SystemMessage

model = init_chat_model("gpt-5-nano")

system_msg = SystemMessage("You are a helpful assistant.")
human_msg = HumanMessage("Hello, how are you?")

# Use with chat models
messages = [system_msg, human_msg]
response = model.invoke(messages)  # Returns AIMessage
```

> [!TIP]
>
> Multi-turn [agents](https://docs.langchain.com/oss/python/langchain/agents.md) accumulate long message histories. [LangSmith](https://docs.langchain.com/langsmith/observability.md) records each turn, tool result, and model response so you can inspect the full conversation. Follow the [tracing quickstart](https://docs.langchain.com/langsmith/trace-with-langchain.md) to enable tracing.
>
> We recommend you also set up [LangSmith Engine](https://docs.langchain.com/langsmith/engine.md) which monitors your traces, detects issues, and proposes fixes.

### Text prompts

Text prompts are strings - ideal for straightforward generation tasks where you don't need to retain conversation history.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
response = model.invoke("Write a haiku about spring")
```

**Use text prompts when:**

* You have a single, standalone request
* You don't need conversation history
* You want minimal code complexity

### Message prompts

Alternatively, you can pass in a list of messages to the model by providing a list of message objects.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.messages import SystemMessage, HumanMessage, AIMessage

messages = [
    SystemMessage("You are a poetry expert"),
    HumanMessage("Write a haiku about spring"),
    AIMessage("Cherry blossoms bloom...")
]
response = model.invoke(messages)
```

**Use message prompts when:**

* Managing multi-turn conversations
* Working with multimodal content (images, audio, files)
* Including system instructions

### Dictionary format

You can also specify messages directly in OpenAI chat completions format.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
messages = [
    {"role": "system", "content": "You are a poetry expert"},
    {"role": "user", "content": "Write a haiku about spring"},
    {"role": "assistant", "content": "Cherry blossoms bloom..."}
]
response = model.invoke(messages)
```

## Message types

* &#x20;[System message](#system-message) - Tells the model how to behave and provide context for interactions
* &#x20;[Human message](#human-message) - Represents user input and interactions with the model
* &#x20;[AI message](#ai-message) - Responses generated by the model, including text content, tool calls, and metadata
* &#x20;[Tool message](#tool-message) - Represents the outputs of [tool calls](https://docs.langchain.com/oss/python/langchain/models.md#tool-calling)

### System message

A [`SystemMessage`](https://reference.langchain.com/python/langchain-core/messages/system/SystemMessage) represent an initial set of instructions that primes the model's behavior. You can use a system message to set the tone, define the model's role, and establish guidelines for responses.

```python Basic instructions theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
system_msg = SystemMessage("You are a helpful coding assistant.")

messages = [
    system_msg,
    HumanMessage("How do I create a REST API?")
]
response = model.invoke(messages)
```

```python Detailed persona theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.messages import SystemMessage, HumanMessage

system_msg = SystemMessage("""
You are a senior Python developer with expertise in web frameworks.
Always provide code examples and explain your reasoning.
Be concise but thorough in your explanations.
""")

messages = [
    system_msg,
    HumanMessage("How do I create a REST API?")
]
response = model.invoke(messages)
```

***

### Human message

A [`HumanMessage`](https://reference.langchain.com/python/langchain-core/messages/human/HumanMessage) represents user input and interactions. They can contain text, images, audio, files, and any other amount of multimodal [content](#message-content).

#### Text content

```python Message object theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
response = model.invoke([
  HumanMessage("What is machine learning?")
])
```

```python String shortcut theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# Using a string is a shortcut for a single HumanMessage
response = model.invoke("What is machine learning?")
```

#### Message metadata

```python Add metadata theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
human_msg = HumanMessage(
    content="Hello!",
    name="alice",  # Optional: identify different users
    id="msg_123",  # Optional: unique identifier for tracing
)
```

> [!NOTE]
>
> The `name` field behavior varies by provider—some use it for user identification, others ignore it. To check, refer to the model provider's [reference](https://reference.langchain.com/python/integrations/).

***

### AI message

An [`AIMessage`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessage) represents the output of a model invocation. They can include multimodal data, tool calls, and provider-specific metadata that you can later access.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
response = model.invoke("Explain AI")
print(type(response))  # <class 'langchain.messages.AIMessage'>
```

[`AIMessage`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessage) objects are returned by the model when calling it, which contains all of the associated metadata in the response.

Providers weigh/contextualize types of messages differently, which means it is sometimes helpful to manually create a new [`AIMessage`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessage) object and insert it into the message history as if it came from the model.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.messages import AIMessage, SystemMessage, HumanMessage

# Create an AI message manually (e.g., for conversation history)
ai_msg = AIMessage("I'd be happy to help you with that question!")

# Add to conversation history
messages = [
    SystemMessage("You are a helpful assistant"),
    HumanMessage("Can you help me?"),
    ai_msg,  # Insert as if it came from the model
    HumanMessage("Great! What's 2+2?")
]

response = model.invoke(messages)
```

> [accordion] Attributes
>
> **text** `string`
>
> The text content of the message.
>
> **content** `string | dict[]`
>
> The raw content of the message.
>
> **content\_blocks** `ContentBlock[]`
>
> The standardized [content blocks](#message-content) of the message.
>
> **tool\_calls** `dict[] | None`
>
> The tool calls made by the model.
>
> Empty if no tools are called.
>
> **id** `string`
>
> A unique identifier for the message (either automatically generated by LangChain or returned in the provider response)
>
> **usage\_metadata** `dict | None`
>
> The usage metadata of the message, which can contain token counts when available.
>
> **response\_metadata** `ResponseMetadata | None`
>
> The response metadata of the message.

#### Tool calls

When models make [tool calls](https://docs.langchain.com/oss/python/langchain/models.md#tool-calling), they're included in the [`AIMessage`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessage):

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.chat_models import init_chat_model

model = init_chat_model("gpt-5-nano")

def get_weather(location: str) -> str:
    """Get the weather at a location."""
    ...

model_with_tools = model.bind_tools([get_weather])
response = model_with_tools.invoke("What's the weather in Paris?")

for tool_call in response.tool_calls:
    print(f"Tool: {tool_call['name']}")
    print(f"Args: {tool_call['args']}")
    print(f"ID: {tool_call['id']}")
```

Other structured data, such as reasoning or citations, can also appear in message [content](https://docs.langchain.com/oss/python/langchain/messages.md#message-content).

#### Token usage

An [`AIMessage`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessage) can hold token counts and other usage metadata in its [`usage_metadata`](https://reference.langchain.com/python/langchain-core/messages/ai/UsageMetadata) field:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.chat_models import init_chat_model

model = init_chat_model("gpt-5-nano")

response = model.invoke("Hello!")
response.usage_metadata
```

```
{'input_tokens': 8,
 'output_tokens': 304,
 'total_tokens': 312,
 'input_token_details': {'audio': 0, 'cache_read': 0},
 'output_token_details': {'audio': 0, 'reasoning': 256}}
```

See [`UsageMetadata`](https://reference.langchain.com/python/langchain-core/messages/ai/UsageMetadata) for details.

#### Streaming and chunks

During streaming, you'll receive [`AIMessageChunk`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessageChunk) objects that can be combined into a full message object:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
chunks = []
full_message = None
for chunk in model.stream("Hi"):
    chunks.append(chunk)
    print(chunk.text)
    full_message = chunk if full_message is None else full_message + chunk
```

> [!NOTE]
>
> Learn more:
>
> * [Streaming tokens from chat models](https://docs.langchain.com/oss/python/langchain/models.md#stream)
> * [Streaming tokens and/or steps from agents](https://docs.langchain.com/oss/python/langchain/streaming.md)

***

### Tool message

For models that support [tool calling](https://docs.langchain.com/oss/python/langchain/models.md#tool-calling), AI messages can contain tool calls. Tool messages are used to pass the results of a single tool execution back to the model.

[Tools](https://docs.langchain.com/oss/python/langchain/tools.md) can generate [`ToolMessage`](https://reference.langchain.com/python/langchain-core/messages/tool/ToolMessage) objects directly. Below, we show a simple example. Read more in the [tools guide](https://docs.langchain.com/oss/python/langchain/tools.md).

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.messages import AIMessage
from langchain.messages import ToolMessage

# After a model makes a tool call
# (Here, we demonstrate manually creating the messages for brevity)
ai_message = AIMessage(
    content=[],
    tool_calls=[{
        "name": "get_weather",
        "args": {"location": "San Francisco"},
        "id": "call_123"
    }]
)

# Execute tool and create result message
weather_result = "Sunny, 72°F"
tool_message = ToolMessage(
    content=weather_result,
    tool_call_id="call_123"  # Must match the call ID
)

# Continue conversation
messages = [
    HumanMessage("What's the weather in San Francisco?"),
    ai_message,  # Model's tool call
    tool_message,  # Tool execution result
]
response = model.invoke(messages)  # Model processes the result
```

> [accordion] Attributes
>
> **content** `string` *required*
>
> The stringified output of the tool call.
>
> **tool\_call\_id** `string` *required*
>
> The ID of the tool call that this message is responding to. Must match the ID of the tool call in the [`AIMessage`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessage).
>
> **name** `string` *required*
>
> The name of the tool that was called.
>
> **artifact** `dict`
>
> Additional data not sent to the model but can be accessed programmatically.

> [!NOTE]
>
> The `artifact` field stores supplementary data that won't be sent to the model but can be accessed programmatically. This is useful for storing raw results, debugging information, or data for downstream processing without cluttering the model's context.
>
> > [accordion] Example: Using artifact for retrieval metadata
> >
> > For example, a [retrieval](https://docs.langchain.com/oss/python/deepagents/retrieval.md) tool could retrieve a passage from a document for reference by a model. Where message `content` contains text that the model will reference, an `artifact` can contain document identifiers or other metadata that an application can use (e.g., to render a page). See example below:
> >
> > ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> > from langchain.messages import ToolMessage
> >
> > # Sent to model
> > message_content = "It was the best of times, it was the worst of times."
> >
> > # Artifact available downstream
> > artifact = {"document_id": "doc_123", "page": 0}
> >
> > tool_message = ToolMessage(
> >     content=message_content,
> >     tool_call_id="call_123",
> >     name="search_books",
> >     artifact=artifact,
> > )
> > ```
> >
> > See the [RAG tutorial](https://docs.langchain.com/oss/python/deepagents/rag.md) for an end-to-end example of building retrieval [agents](https://docs.langchain.com/oss/python/langchain/agents.md) with LangChain.

***

## Message content

You can think of a message's content as the payload of data that gets sent to the model. Messages have a `content` attribute that is loosely-typed, supporting strings and lists of untyped objects (e.g., dictionaries). This allows support for provider-native structures directly in LangChain chat models, such as [multimodal](#multimodal) content and other data.

Separately, LangChain provides dedicated content types for text, reasoning, citations, multi-modal data, server-side tool calls, and other message content. See [content blocks](#standard-content-blocks) below.

LangChain chat models accept message content in the `content` attribute.

This may contain either:

1. A string
2. A list of content blocks in a provider-native format
3. A list of [LangChain's standard content blocks](#standard-content-blocks)

See below for an example using [multimodal](#multimodal) inputs:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.messages import HumanMessage

# String content
human_message = HumanMessage("Hello, how are you?")

# Provider-native format (e.g., OpenAI)
human_message = HumanMessage(content=[
    {"type": "text", "text": "Hello, how are you?"},
    {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
])

# List of standard content blocks
human_message = HumanMessage(content_blocks=[
    {"type": "text", "text": "Hello, how are you?"},
    {"type": "image", "url": "https://example.com/image.jpg"},
])
```

> [!TIP]
>
> Specifying `content_blocks` when initializing a message will still populate message
> `content`, but provides a type-safe interface for doing so.

### Standard content blocks

LangChain provides a standard representation for message content that works across providers.

Message objects implement a `content_blocks` property that will lazily parse the `content` attribute into a standard, type-safe representation. For example, messages generated from [`ChatAnthropic`](https://docs.langchain.com/oss/python/integrations/chat/anthropic) or [`ChatOpenAI`](https://docs.langchain.com/oss/python/integrations/chat/openai) will include `thinking` or `reasoning` blocks in the format of the respective provider, but can be lazily parsed into a consistent [`ReasoningContentBlock`](#content-block-reference) representation:

> [tab] Anthropic
>
> ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> from langchain.messages import AIMessage
>
> message = AIMessage(
>     content=[
>         {"type": "thinking", "thinking": "...", "signature": "WaUjzkyp..."},
>         {"type": "text", "text": "..."},
>     ],
>     response_metadata={"model_provider": "anthropic"}
> )
> message.content_blocks
> ```
>
> ```
> [{'type': 'reasoning',
>   'reasoning': '...',
>   'extras': {'signature': 'WaUjzkyp...'}},
>  {'type': 'text', 'text': '...'}]
> ```

> [tab] OpenAI
>
> ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> from langchain.messages import AIMessage
>
> message = AIMessage(
>     content=[
>         {
>             "type": "reasoning",
>             "id": "rs_abc123",
>             "summary": [
>                 {"type": "summary_text", "text": "summary 1"},
>                 {"type": "summary_text", "text": "summary 2"},
>             ],
>         },
>         {"type": "text", "text": "...", "id": "msg_abc123"},
>     ],
>     response_metadata={"model_provider": "openai"}
> )
> message.content_blocks
> ```
>
> ```
> [{'type': 'reasoning', 'id': 'rs_abc123', 'reasoning': 'summary 1'},
>  {'type': 'reasoning', 'id': 'rs_abc123', 'reasoning': 'summary 2'},
>  {'type': 'text', 'text': '...', 'id': 'msg_abc123'}]
> ```

See the [integrations guides](https://docs.langchain.com/oss/python/integrations/providers/overview.md) to get started with the
inference provider of your choice.

> [!NOTE]
>
> **Serializing standard content**
>
> If an application outside of LangChain needs access to the standard content block
> representation, you can opt-in to storing content blocks in message content.
>
> To do this, you can set the `LC_OUTPUT_VERSION` environment variable to `v1`. Or,
> initialize any chat model with `output_version="v1"`:
>
> ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> from langchain.chat_models import init_chat_model
>
> model = init_chat_model("gpt-5-nano", output_version="v1")
> ```

### Multimodal

**Multimodality** refers to the ability to work with data that comes in different
forms, such as text, audio, images, and video. LangChain includes standard types
for these data that can be used across providers.

[Chat models](https://docs.langchain.com/oss/python/langchain/models.md) can accept multimodal data as input and generate
it as output. Below we show short examples of input messages featuring multimodal data.

> [!NOTE]
>
> Extra keys can be included top-level in the content block or nested in `"extras": {"key": value}`.
>
> [OpenAI](https://docs.langchain.com/oss/python/integrations/chat/openai),
> for example, requires a filename for PDFs. See the [provider page](https://docs.langchain.com/oss/python/integrations/providers/overview.md)
> for your chosen model for specifics.

```python Image input theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# From URL
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this image."},
        {"type": "image", "url": "https://example.com/path/to/image.jpg"},
    ]
}

# From base64 data
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this image."},
        {
            "type": "image",
            "base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
            "mime_type": "image/jpeg",
        },
    ]
}

# From provider-managed File ID
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this image."},
        {"type": "image", "file_id": "file-abc123"},
    ]
}
```

```python PDF document input theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# From URL
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this document."},
        {"type": "file", "url": "https://example.com/path/to/document.pdf"},
    ]
}

# From base64 data
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this document."},
        {
            "type": "file",
            "base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
            "mime_type": "application/pdf",
        },
    ]
}

# From provider-managed File ID
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this document."},
        {"type": "file", "file_id": "file-abc123"},
    ]
}
```

```python Audio input theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# From base64 data
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this audio."},
        {
            "type": "audio",
            "base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
            "mime_type": "audio/wav",
        },
    ]
}

# From provider-managed File ID
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this audio."},
        {"type": "audio", "file_id": "file-abc123"},
    ]
}
```

```python Video input theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# From base64 data
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this video."},
        {
            "type": "video",
            "base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
            "mime_type": "video/mp4",
        },
    ]
}

# From provider-managed File ID
message = {
    "role": "user",
    "content": [
        {"type": "text", "text": "Describe the content of this video."},
        {"type": "video", "file_id": "file-abc123"},
    ]
}
```

> [!WARNING]
>
> Not all models support all file types. Check the model provider's [reference](https://reference.langchain.com/python/integrations/) for supported formats and size limits.

### Content block reference

Content blocks are represented (either when creating a message or accessing the `content_blocks` property) as a list of typed dictionaries. Each item in the list must adhere to one of the following block types:

> [accordion] Core
>
> > [accordion] TextContentBlock
> >
> > **Purpose:** Standard text output
> >
> > **type** `string` *required*
> >
> > Always `"text"`
> >
> > **text** `string` *required*
> >
> > The text content
> >
> > **annotations** `object[]`
> >
> > List of annotations for the text
> >
> > **extras** `object`
> >
> > Additional provider-specific data
> >
> > **Example:**
> >
> > ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> > {
> >     "type": "text",
> >     "text": "Hello world",
> >     "annotations": []
> > }
> > ```
>
> > [accordion] ReasoningContentBlock
> >
> > **Purpose:** Model reasoning steps
> >
> > **type** `string` *required*
> >
> > Always `"reasoning"`
> >
> > **reasoning** `string`
> >
> > The reasoning content
> >
> > **extras** `object`
> >
> > Additional provider-specific data
> >
> > **Example:**
> >
> > ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> > {
> >     "type": "reasoning",
> >     "reasoning": "The user is asking about...",
> >     "extras": {"signature": "abc123"},
> > }
> > ```
>
> > [accordion] RefusalContentBlock
> >
> > **Purpose:** An explicit refusal that the model provider reports, such as an OpenAI `refusal` content part, an Anthropic `stop_reason="refusal"`, or a Gemini safety block. LangChain does not detect refusals that the model writes as ordinary text. Requires `langchain-core>=1.7.5`.
> >
> > **type** `string` *required*
> >
> > Always `"refusal"`
> >
> > **refusal** `string` *required*
> >
> > The refusal message, or an empty string if the provider sent none
> >
> > **extras** `object`
> >
> > Additional provider-specific data, such as Anthropic's refusal `category` or Gemini's `finish_reason` or `block_reason`
> >
> > **Example:**
> >
> > ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> > {
> >     "type": "refusal",
> >     "refusal": "",
> >     "extras": {"category": "cyber"},
> > }
> > ```

> [accordion] Multimodal
>
> > [accordion] ImageContentBlock
> >
> > **Purpose:** Image data
> >
> > **type** `string` *required*
> >
> > Always `"image"`
> >
> > **url** `string`
> >
> > URL pointing to the image location.
> >
> > **base64** `string`
> >
> > Base64-encoded image data.
> >
> > **id** `string`
> >
> > Unique identifier for this content block (either generated by the provider or by LangChain).
> >
> > **mime\_type** `string`
> >
> > Image [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml#image) (e.g., `image/jpeg`, `image/png`). Required for base64 data.
>
> > [accordion] AudioContentBlock
> >
> > **Purpose:** Audio data
> >
> > **type** `string` *required*
> >
> > Always `"audio"`
> >
> > **url** `string`
> >
> > URL pointing to the audio location.
> >
> > **base64** `string`
> >
> > Base64-encoded audio data.
> >
> > **id** `string`
> >
> > Unique identifier for this content block (either generated by the provider or by LangChain).
> >
> > **mime\_type** `string`
> >
> > Audio [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml#audio) (e.g., `audio/mpeg`, `audio/wav`). Required for base64 data.
>
> > [accordion] VideoContentBlock
> >
> > **Purpose:** Video data
> >
> > **type** `string` *required*
> >
> > Always `"video"`
> >
> > **url** `string`
> >
> > URL pointing to the video location.
> >
> > **base64** `string`
> >
> > Base64-encoded video data.
> >
> > **id** `string`
> >
> > Unique identifier for this content block (either generated by the provider or by LangChain).
> >
> > **mime\_type** `string`
> >
> > Video [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml#video) (e.g., `video/mp4`, `video/webm`). Required for base64 data.
>
> > [accordion] FileContentBlock
> >
> > **Purpose:** Generic files (PDF, etc)
> >
> > **type** `string` *required*
> >
> > Always `"file"`
> >
> > **url** `string`
> >
> > URL pointing to the file location.
> >
> > **base64** `string`
> >
> > Base64-encoded file data.
> >
> > **id** `string`
> >
> > Unique identifier for this content block (either generated by the provider or by LangChain).
> >
> > **mime\_type** `string`
> >
> > File [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml) (e.g., `application/pdf`). Required for base64 data.
>
> > [accordion] PlainTextContentBlock
> >
> > **Purpose:** Document text (`.txt`, `.md`)
> >
> > **type** `string` *required*
> >
> > Always `"text-plain"`
> >
> > **text** `string`
> >
> > The text content
> >
> > **mime\_type** `string`
> >
> > [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml) of the text (e.g., `text/plain`, `text/markdown`)

> [accordion] Tool Calling
>
> > [accordion] ToolCall
> >
> > **Purpose:** Function calls
> >
> > **type** `string` *required*
> >
> > Always `"tool_call"`
> >
> > **name** `string` *required*
> >
> > Name of the tool to call
> >
> > **args** `object` *required*
> >
> > Arguments to pass to the tool
> >
> > **id** `string` *required*
> >
> > Unique identifier for this tool call
> >
> > **Example:**
> >
> > ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> > {
> >     "type": "tool_call",
> >     "name": "search",
> >     "args": {"query": "weather"},
> >     "id": "call_123"
> > }
> > ```
>
> > [accordion] ToolCallChunk
> >
> > **Purpose:** Streaming tool call fragments
> >
> > **type** `string` *required*
> >
> > Always `"tool_call_chunk"`
> >
> > **name** `string`
> >
> > Name of the tool being called
> >
> > **args** `string`
> >
> > Partial tool arguments (may be incomplete JSON)
> >
> > **id** `string`
> >
> > Tool call identifier
> >
> > **index** `number | string`
> >
> > Position of this chunk in the stream
>
> > [accordion] InvalidToolCall
> >
> > **Purpose:** Malformed calls, intended to catch JSON parsing errors.
> >
> > **type** `string` *required*
> >
> > Always `"invalid_tool_call"`
> >
> > **name** `string`
> >
> > Name of the tool that failed to be called
> >
> > **args** `object`
> >
> > Arguments to pass to the tool
> >
> > **error** `string`
> >
> > Description of what went wrong

> [accordion] Server-Side Tool Execution
>
> > [accordion] ServerToolCall
> >
> > **Purpose:** Tool call that is executed server-side.
> >
> > **type** `string` *required*
> >
> > Always `"server_tool_call"`
> >
> > **id** `string` *required*
> >
> > An identifier associated with the tool call.
> >
> > **name** `string` *required*
> >
> > The name of the tool to be called.
> >
> > **args** `string` *required*
> >
> > Partial tool arguments (may be incomplete JSON)
>
> > [accordion] ServerToolCallChunk
> >
> > **Purpose:** Streaming server-side tool call fragments
> >
> > **type** `string` *required*
> >
> > Always `"server_tool_call_chunk"`
> >
> > **id** `string`
> >
> > An identifier associated with the tool call.
> >
> > **name** `string`
> >
> > Name of the tool being called
> >
> > **args** `string`
> >
> > Partial tool arguments (may be incomplete JSON)
> >
> > **index** `number | string`
> >
> > Position of this chunk in the stream
>
> > [accordion] ServerToolResult
> >
> > **Purpose:** Search results
> >
> > **type** `string` *required*
> >
> > Always `"server_tool_result"`
> >
> > **tool\_call\_id** `string` *required*
> >
> > Identifier of the corresponding server tool call.
> >
> > **id** `string`
> >
> > Identifier associated with the server tool result.
> >
> > **status** `string` *required*
> >
> > Execution status of the server-side tool. `"success"` or `"error"`.
> >
> > **output**
> >
> > Output of the executed tool.

> [accordion] Provider-Specific Blocks
>
> > [accordion] NonStandardContentBlock
> >
> > **Purpose:** Provider-specific escape hatch
> >
> > **type** `string` *required*
> >
> > Always `"non_standard"`
> >
> > **value** `object` *required*
> >
> > Provider-specific data structure
> >
> > **Usage:** For experimental or provider-unique features
> >
> > When `langchain-core` adds a standard block type, payloads that match it move out of `non_standard` and into the new type. Branch on `type` instead of relying on a payload staying `non_standard`, and upgrade provider packages together with `langchain-core`.
>
> Additional provider-specific content types may be found within the [reference documentation](https://docs.langchain.com/oss/python/integrations/providers/overview.md) of each model provider.

> [!TIP]
>
> View the canonical type definitions in the [API reference](https://reference.langchain.com/python/langchain/messages).

> [!NOTE]
>
> Content blocks were introduced as a new property on messages in LangChain v1 to standardize content formats across providers while maintaining backward compatibility with existing code.
>
> Content blocks are not a replacement for the [`content`](https://reference.langchain.com/python/langchain-core/messages/base/BaseMessage) property, but rather a new property that can be used to access the content of a message in a standardized format.

## Serialization

You can serialize messages to plain objects for storage and deserialize back to message instances. This is useful for persisting conversation history and resuming sessions.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.messages import HumanMessage
from langchain_core.load import dumpd, load

message = HumanMessage("What is the capital of France?")

# Serialize to a plain dict
serialized = dumpd(message)

# Deserialize back to a message object
restored = load(serialized)
```

> [!WARNING]
>
> **`load()` instantiates Python objects and can trigger side effects during deserialization. Never call `load()` on data from an untrusted or unauthenticated source.**

## Use with chat models

[Chat models](https://docs.langchain.com/oss/python/langchain/models.md) accept a sequence of message objects as input and return an [`AIMessage`](https://reference.langchain.com/python/langchain-core/messages/ai/AIMessage) as output. Interactions are often stateless, so that a simple conversational loop involves invoking a model with a growing list of messages.

Refer to the below guides to learn more:

* Built-in features for [persisting and managing conversation histories](https://docs.langchain.com/oss/python/langchain/short-term-memory.md)
* Strategies for managing context windows, including [trimming and summarizing messages](https://docs.langchain.com/oss/python/langchain/short-term-memory.md#common-patterns)

***

[Connect these docs](https://docs.langchain.com/use-these-docs.md) to your agent of choice via MCP for real-time answers.

[Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/messages.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
