1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
46 small wins to finish your pathNext lesson →
Content blocks: images and files in a message
Content blocks are the typed parts of a message, so one message can carry text alongside an image, a file or a PDF instead of a plain string.
Last updated: 27 Sep, 2026 · LangChain 1.4
A message so far held a string. To ask about a picture or a document, the message needs parts: some text and some media. That is what content_blocks is.
Building a message with parts
Pass content_blocks a list of typed parts. Each part names its type and its data.
from langchain.messages import HumanMessage
msg = HumanMessage(content_blocks=[
{"type": "text", "text": "What is in this picture?"},
{"type": "image", "url": "https://example.com/cat.png"},
])A text-and-image message end to end
The whole snippet, printing the block types the message carries.
from langchain.messages import HumanMessage
msg = HumanMessage(content_blocks=[
{"type": "text", "text": "What is in this picture?"},
{"type": "image", "url": "https://example.com/cat.png"},
])
print([b["type"] for b in msg.content_blocks])What the message holds
- The message carries two parts: a
textblock and animageblock. content_blocksgives every part atype, so a model that accepts images reads them.- A plain-string message is the one-block case: only text.
Plain string vs content blocks
| content="..." | content_blocks=[...] | |
|---|---|---|
| Carries | Text only | Text, images, files, audio |
| Use for | An ordinary turn | Asking about a picture or a document |
| Model support | Every chat model | Models that accept that media |
When a message needs media
- Asking a vision model what is in an image.
- Sending a PDF or a file for the model to read.
- Mixing an instruction with the media it refers to.
Watch out. A model only reads a block type it supports. Send an image to a text-only model and the image is ignored or rejected; check the model accepts that media first.
Related
- Previous: Messages: a conversation as a list
- Next: BaseChatModel: a model of your own
- Reference: LangChain docs
Try it yourself
- Add a third block for a file with a
urland print the types. - Send the message to a real vision model and read its answer.
- Build the same message with a base64 image instead of a url.
Slow is fine. Stopping is the only problem.