LangChainLangChain 1.4 · Python 3.10+
0%
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.

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

Example
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 text block and an image block.
  • content_blocks gives every part a type, 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=[...]
CarriesText onlyText, images, files, audio
Use forAn ordinary turnAsking about a picture or a document
Model supportEvery chat modelModels 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.
Try it yourself
  • Add a third block for a file with a url and 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.