message_utils Module
Conversion and serialization helpers for OTEL gen-ai message format.
Provides normalization from plain list[str] (backward compat) to the
structured array format, and a non-throwing serialize_messages function.
Functions
is_string_list
Return True when param is a plain list[str].
is_string_list(param: str | list[str] | InputMessages | OutputMessages) -> bool
Parameters
| Name | Description |
|---|---|
|
param
Required
|
|
is_wrapped_messages
Return True when param is a structured message container.
is_wrapped_messages(param: str | list[str] | InputMessages | OutputMessages) -> bool
Parameters
| Name | Description |
|---|---|
|
param
Required
|
|
normalize_input_messages
Normalize an InputMessagesParam to an InputMessages container.
str-> wrapped in a single-element list, then converted.list[str]-> converted toChatMessagelist and wrapped.InputMessages-> returned as-is.
normalize_input_messages(param: str | list[str] | InputMessages) -> InputMessages
Parameters
| Name | Description |
|---|---|
|
param
Required
|
|
normalize_output_messages
Normalize an OutputMessagesParam to an OutputMessages container.
str-> wrapped in a single-element list, then converted.list[str]-> converted toOutputMessagelist and wrapped.OutputMessages-> returned as-is.
normalize_output_messages(param: str | list[str] | OutputMessages) -> OutputMessages
Parameters
| Name | Description |
|---|---|
|
param
Required
|
|
serialize_messages
Serialize a message container to a JSON array.
The output is a plain JSON array of message objects per OTel spec:
[{"role":"user","parts":[...]}].
The try/except ensures telemetry recording is non-throwing even when message parts contain non-JSON-serializable values.
serialize_messages(wrapper: InputMessages | OutputMessages) -> str
Parameters
| Name | Description |
|---|---|
|
wrapper
Required
|
|
to_input_messages
Convert plain input strings into OTEL ChatMessage objects.
to_input_messages(messages: list[str]) -> list[microsoft.opentelemetry.a365.core.models.messages.ChatMessage]
Parameters
| Name | Description |
|---|---|
|
messages
Required
|
|
to_output_messages
Convert plain output strings into OTEL OutputMessage objects.
to_output_messages(messages: list[str]) -> list[microsoft.opentelemetry.a365.core.models.messages.OutputMessage]
Parameters
| Name | Description |
|---|---|
|
messages
Required
|
|