By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A modern reply can contain text, a request to call a tool, a summary of the model's reasoning, an image or a file. Providers encode those parts differently, so branching on .content couples your code to one provider's format. LangChain 1.x adds .content_blocks: the same message, parsed lazily into a standard typed list you can branch on safely.
| Block type | What it holds | Typical use |
|---|---|---|
text | A string of model text | Showing the answer to the customer |
tool_call | Tool name, arguments and call id | Handing work to a tool (Lesson 4) |
reasoning | The model's thinking summary, when the provider exposes it | Auditing decisions; keep it out of customer UI by default |
image / file | URL, base64 data or a provider file id | Multimodal requests and receipts |
non_standard | A provider-specific escape hatch | Only when no standard block fits your use case |
from langchain.messages import AIMessage, ToolCall
# A message as it might look after a model decided to use a tool.
reply = AIMessage(
content=[{"type": "text", "text": "Checking order #4521."}],
tool_calls=[
ToolCall(name="lookup_order", args={"order_id": "4521"}, id="call_1")
],
)
for block in reply.content_blocks:
kind = block["type"]
if kind == "text":
print("text:", block["text"])
elif kind == "tool_call":
print("tool call:", block["name"], block["args"])
elif kind == "reasoning":
print("reasoning:", block["reasoning"]).content?You can: for plain text, .content is all you need. The moment you care about tool calls or reasoning, the raw format differs by provider — Anthropic returns thinking blocks, OpenAI returns reasoning summaries, and both normalise to a reasoning block in .content_blocks. Writing one loop against the standard shape is cheaper than maintaining one code path per provider. The raw content is still there when you need the original.
Sometimes the next step is code, not prose: you need the intent, the order id and an urgency score so you can route a ticket. A Pydantic model gives the model a schema, and with_structured_output returns a validated instance instead of a sentence you have to parse.
from langchain.chat_models import init_chat_model
from pydantic import BaseModel, Field
class TicketSummary(BaseModel):
"""A compact summary of one support ticket."""
order_id: str = Field(description="Order id mentioned by the customer")
intent: str = Field(
description="One of: order_status, refund, replacement, other"
)
urgency: int = Field(description="1-5", ge=1, le=5)
model = init_chat_model("openai:gpt-4.1-mini", temperature=0)
structured = model.with_structured_output(TicketSummary)
summary = structured.invoke(
"My order #4521 arrived cracked. I need a replacement before Friday."
)
print(summary)PydanticOutputParser is the other direction: it parses text you already have — a logged response, a fixture, a provider that does not support structured output — into the same Pydantic object. Its get_format_instructions() output is the prompt fragment that tells a model how to produce text the parser can read.
from langchain_core.output_parsers import PydanticOutputParser
from pydantic import BaseModel, Field
class TicketSummary(BaseModel):
"""A compact summary of one support ticket."""
order_id: str = Field(description="Order id mentioned by the customer")
intent: str = Field(
description="One of: order_status, refund, replacement, other"
)
urgency: int = Field(description="1-5", ge=1, le=5)
parser = PydanticOutputParser(pydantic_object=TicketSummary)
raw = '{"order_id": "4521", "intent": "replacement", "urgency": 4}'
print(parser.parse(raw))Key takeaways
.content_blocks is the standard, typed view of a reply; branch on type, not on provider wire formats.
Text, tool calls, reasoning, images and files all arrive as blocks; unknown parts fall back to non_standard.
with_structured_output(Schema) makes the model return a validated Pydantic object.
PydanticOutputParser parses existing text into the same model — useful for tests and for providers that lack structured output.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.