LangChain.OpenTelemetry.MessageSerializer (LangChain v0.9.1)

Copy Markdown View Source

Serializes LangChain Message structs to JSON strings following the gen_ai.input.messages / gen_ai.output.messages GenAI Semantic Convention schema.

The Erlang OpenTelemetry SDK uses flat key-value attributes, so messages are serialized as a JSON string rather than nested structures.

Summary

Functions

Serializes a list of messages to a JSON string for gen_ai.input.messages.

Serializes a result (single message or list of messages) to a JSON string for gen_ai.output.messages.

Functions

serialize_input(messages)

@spec serialize_input([LangChain.Message.t()]) :: String.t()

Serializes a list of messages to a JSON string for gen_ai.input.messages.

Each message is represented as a map with role and content keys. Tool calls are included under the tool_calls key when present.

serialize_output(message)

@spec serialize_output(LangChain.Message.t() | [LangChain.Message.t()]) :: String.t()

Serializes a result (single message or list of messages) to a JSON string for gen_ai.output.messages.