Send a link to your students to track their progress
21 Terms
1
New cards
2
New cards
3
New cards
4
New cards
5
New cards
What three kinds of data can a message's content contain in LangChain?
A plain string; a list of provider-format blocks (the native format of a specific model); or a list of LangChain standard blocks (content_blocks).
6
New cards
What happens to a message's `content` when you specify `content_blocks` at initialization?
`content_blocks` is just a convenient wrapper — the actual data still ends up populating the message's `content`.
7
New cards
Why does content format flexibility matter for multimodality?
Modern models accept not just text but images; audio; and video; and a list of blocks lets you pass all of that in one message.
8
New cards
Why does LangChain support both native provider formats and its own standard format for content?
Because different APIs (OpenAI; Anthropic; Google) use different formats for multimodal data; so LangChain lets you write in either the provider's native format or its own standard one and converts as needed.
9
New cards
What problem does `content_blocks` solve regarding model reasoning across providers?
Different providers return different formats for the same concept — e.g. Anthropic calls it `thinking` (with a `signature`) while OpenAI calls it `reasoning` (or `reasoning_content`) — so without standardization you'd need separate code per provider.
10
New cards
How does the `content_blocks` property behave when accessed on a message?
It lazily parses `content`; converting the provider format into the standard LangChain format only when it's accessed.
11
New cards
When an Anthropic `thinking` block is converted via `content_blocks`; what does its type become?
`reasoning`.
12
New cards
When an Anthropic `thinking` block is converted via `content_blocks`; where does the `signature` field end up?
Inside `extras`; e.g. `extras: {\signature\': \'...\'}`.'
13
New cards
What three benefits does `content_blocks` provide; according to the notes?
Unified code (write handling once; works across OpenAI; Anthropic; Google; etc.); type safety (returns strictly typed objects; not raw dicts); and laziness (conversion only happens on access; avoiding wasted resources).
14
New cards
By default; are `content_blocks` persisted into `content` during serialization?
No — by default they are not persisted into `content` during serialization; such as when saving to JSON or a database.
15
New cards
What must you do if an external application needs the standard `content_blocks` format saved directly into `content`?
Enable `v1` mode; via the `LC_OUTPUT_VERSION` environment variable or the `output_version` parameter at model initialization.
16
New cards
After enabling `v1` mode; what will a message's `content` directly contain?
Standard blocks instead of the provider format.
17
New cards
python from langchain.messages import HumanMessage # 1. Just a string msg = HumanMessage('Hello!') # 2. Native OpenAI format (provider-specific) msg = HumanMessage(content=[ {'type': 'text'; 'text': 'What's in this image?'}; {'type': 'image_url'; 'image_url': {'url': 'https://example.com/image.jpg'}} ]) # 3. Standard LangChain format (type-safe) msg = HumanMessage(________=[ {'type': 'text'; 'text': 'What's in this image?'}; {'type': 'image'; 'url': 'https://example.com/image.jpg'}; ])
```python from langchain.messages import HumanMessage # 1. Just a string msg = HumanMessage('Hello!') # 2. Native OpenAI format (provider-specific) msg = HumanMessage(content=[ {'type': 'text'; 'text': 'What's in this image?'}; {'type': 'image_url'; 'image_url': {'url': 'https://example.com/image.jpg'}} ]) # 3. Standard LangChain format (type-safe) msg = HumanMessage(content_blocks=[ {'type': 'text'; 'text': 'What's in this image?'}; {'type': 'image'; 'url': 'https://example.com/image.jpg'}; ]) ```
18
New cards
python from langchain.messages import AIMessage # Message from Anthropic in NATIVE format message = AIMessage( content=[ {'type': 'thinking'; 'thinking': '...'; 'signature': 'WaUjzkyp...'}; {'type': 'text'; 'text': '...'}; ]; response_metadata={'model_provider': 'anthropic'} ) # Access content_blocks — get the STANDARD format message.________
```python from langchain.messages import AIMessage # Message from Anthropic in NATIVE format message = AIMessage( content=[ {'type': 'thinking'; 'thinking': '...'; 'signature': 'WaUjzkyp...'}; {'type': 'text'; 'text': '...'}; ]; response_metadata={'model_provider': 'anthropic'} ) # Access content_blocks — get the STANDARD format message.content_blocks ```
19
New cards
python # Option 1: via environment variable import os os.environ['________'] = 'v1' # Option 2: at model initialization from langchain.chat_models import init_chat_model model = init_chat_model('gpt-5-nano'; ________='v1')
```python # Option 1: via environment variable import os os.environ['LC_OUTPUT_VERSION'] = 'v1' # Option 2: at model initialization from langchain.chat_models import init_chat_model model = init_chat_model('gpt-5-nano'; output_version='v1') ```