content.py — langchain Source File
Architecture documentation for content.py, a python file in the langchain codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR c358607b_1e3a_d544_d7ab_d4bb8c109fd6["content.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] c358607b_1e3a_d544_d7ab_d4bb8c109fd6 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] c358607b_1e3a_d544_d7ab_d4bb8c109fd6 --> 91721f45_4909_e489_8c1f_084f8bd87145 afb01135_7b40_b00b_9769_21eebcc09aa3["langchain_core.utils.utils"] c358607b_1e3a_d544_d7ab_d4bb8c109fd6 --> afb01135_7b40_b00b_9769_21eebcc09aa3 style c358607b_1e3a_d544_d7ab_d4bb8c109fd6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Standard, multimodal content blocks for Large Language Model I/O.
This module provides standardized data structures for representing inputs to and outputs
from LLMs. The core abstraction is the **Content Block**, a `TypedDict`.
**Rationale**
Different LLM providers use distinct and incompatible API schemas. This module provides
a unified, provider-agnostic format to facilitate these interactions. A message to or
from a model is simply a list of content blocks, allowing for the natural interleaving
of text, images, and other content in a single ordered sequence.
An adapter for a specific provider is responsible for translating this standard list of
blocks into the format required by its API.
**Extensibility**
Data **not yet mapped** to a standard block may be represented using the
`NonStandardContentBlock`, which allows for provider-specific data to be included
without losing the benefits of type checking and validation.
Furthermore, provider-specific fields **within** a standard block are fully supported
by default in the `extras` field of each block. This allows for additional metadata
to be included without breaking the standard structure. For example, Google's thought
signature:
```python
AIMessage(
content=[
{
"type": "text",
"text": "J'adore la programmation.",
"extras": {"signature": "EpoWCpc..."}, # Thought signature
}
], ...
)
```
!!! note
Following widespread adoption of [PEP 728](https://peps.python.org/pep-0728/), we
intend to add `extra_items=Any` as a param to Content Blocks. This will signify to
type checkers that additional provider-specific fields are allowed outside of the
`extras` field, and that will become the new standard approach to adding
provider-specific metadata.
??? note
**Example with PEP 728 provider-specific fields:**
```python
# Content block definition
# NOTE: `extra_items=Any`
class TextContentBlock(TypedDict, extra_items=Any):
type: Literal["text"]
id: NotRequired[str]
text: str
annotations: NotRequired[list[Annotation]]
index: NotRequired[int]
// ... (1429 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- langchain_core.utils.utils
- typing
- typing_extensions
Source
Frequently Asked Questions
What does content.py do?
content.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in content.py?
content.py defines 12 function(s): _get_data_content_block_types, create_audio_block, create_citation, create_file_block, create_image_block, create_non_standard_block, create_plaintext_block, create_reasoning_block, create_text_block, create_tool_call, and 2 more.
What does content.py depend on?
content.py imports 3 module(s): langchain_core.utils.utils, typing, typing_extensions.
Where is content.py in the architecture?
content.py is located at libs/core/langchain_core/messages/content.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/core/langchain_core/messages).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free