Printing data¶
In Draive you often need to surface multimodal data in logs, dashboards, or CLI output. Every model state exposes a few helpers that flatten structured content into printable strings:
| Helper | Output |
|---|---|
x.to_mapping() (default) |
dict representation |
x.to_json(indent: int \| None = None) |
JSON string |
x.to_str() |
Model-defined string |
str(x) |
Alias for str(x.to_mapping()) on DataModel |
Different DataModel instances implement .to_str() in their own way, so the rendered view varies
by content type. The sections below walk through the most common multimodal classes and show how
their printing helpers behave.
TextContent¶
Plain text output that mirrors the original text value without any extra markup or quoting.
Example:
ResourceContent¶
Generates a Markdown media reference. Depending on include_data, the reference either embeds the
base64 payload directly or uses a redacted placeholder.
Note
When include_data=True, ResourceContent.to_str() returns the full base64 payload:
Example:
resource: ResourceContent = ResourceContent.of(b'FF', mime_type='application/octet-stream')
ctx.log_info(resource.to_str(include_data=True))
With the default include_data=False, it emits a placeholder that keeps the media type visible
without leaking the bytes:
Example:
with open('./src/dog.jpg', 'rb') as img:
img_data: bytes = img.read()
resource: ResourceContent = ResourceContent.of(img_data, mime_type='image/jpeg')
ctx.log_info(resource.to_str())
ArtifactContent¶
Produces delegated artifact output when visible, otherwise suppresses content entirely for hidden artifacts.
Hidden artifacts render as an empty string:
Visible artifacts reuse the nested artifact’s to_str() result:
MultimodalTag¶
Formats XML-like tags, optionally wrapping the rendered child content. Empty content yields a self-closing tag.
When self.content is empty, the printer emits a self-closing tag:
Example:
Otherwise it wraps the rendered child content:
Example:
Important
`MultimodalTag` is the only multimodal element that exposes metadata inline. Values stored in `meta` appear as XML-style tag attributes.
MultimodalContent¶
Concatenates the string form of each part, resulting in a single composite response without delimiters.
Example:
from draive import MultimodalContent, TextContent, ctx
multimodal: MultimodalContent = MultimodalContent.of(
TextContent.of('Hello '),
TextContent.of('World!'),
)
ctx.log_info(multimodal.to_str())
Result: