Skip to content

API Reference parrot.outputs.a2ui.serialization

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.outputs.a2ui.serialization

View source

A2UI serialization layer — the sole owner of the protocol version field.

Every A2UI v1.0 message on the wire is an envelope by key: {"version": "v1.0", "<messageKey>": {...}} with exactly one message key besides version. Per spec FEAT-470 (G3), that field is written in exactly one place: this module. The inner message models (:mod:parrot.outputs.a2ui.models) never default or write it themselves.

Responsibilities:

  • Serialize any inner A2UI message (CreateSurface, ActionMessage, ...) — or an already-built envelope (:class:~parrot.outputs.a2ui.models.A2UIAgentMessage / :class:~parrot.outputs.a2ui.models.A2UIRendererMessage) — to a JSON dict or a JSONL line, injecting version.
  • Deserialize incoming JSON/JSONL into the correct envelope model. Legacy (pre-v1.0) payloads are detected and normalized via :mod:parrot.outputs.a2ui.compat first, with a DeprecationWarning (spec G5 — compat is read-only; nothing here ever emits the legacy shape).

Attribute A2UI_VERSION

Attribute VERSION_FIELD

Function deserialize

Deserialize wire JSON into the correct A2UI v1.0 envelope.

Legacy (pre-v1.0) payloads ("messageType" in data) are normalized via :mod:parrot.outputs.a2ui.compat first, emitting a DeprecationWarning. A legacy updateDataModel with multiple contents keys normalizes to several v1.0 envelopes — the ONE case where this function returns a list.

deserialize(data: dict[str, Any] | str | bytes) -> A2UIAgentMessage | A2UIRendererMessage | list[A2UIAgentMessage]

Parameter Type Default Description
data dict[str, Any] | str | bytes A JSON dict, or a JSON string/bytes payload.

Returns: A2UIAgentMessage | A2UIRendererMessage | list[A2UIAgentMessage] — The validated envelope (or a list of envelopes, for the legacy multi-content updateDataModel case).

Raises:

  • pydantic.ValidationError — If the payload does not validate as a v1.0 envelope.
  • TypeError — If the payload is not a JSON object.
  • ValueError — If its legacy messageType is unsupported (see :func:compat.normalize_legacy), or its envelope keys are unrecognized.

Function iter_jsonl

Parse a JSONL payload into A2UI envelopes, one per non-empty line.

iter_jsonl(text: str) -> Iterator[A2UIAgentMessage | A2UIRendererMessage]

Parameter Type Default Description
text str A JSONL string.

Returns: Iterator[A2UIAgentMessage | A2UIRendererMessage]

Function serialize

Serialize an A2UI message to a JSON-ready envelope dict.

Accepts either a concrete inner message (CreateSurface, ...) or an already-built envelope (A2UIAgentMessage/A2UIRendererMessage).

serialize(message: Serializable) -> dict[str, Any]

Parameter Type Default Description
message Serializable Any A2UI inner message or envelope instance.

Returns: dict[str, Any] — {"version": "v1.0", "<messageKey>": {...}} — exactly two keys.

Raises:

  • TypeError — If message is not a recognized A2UI message type.

Function to_jsonl

Serialize one or more messages to JSONL (one complete envelope per line).

to_jsonl(messages: Serializable | Iterable[Serializable]) -> str

Parameter Type Default Description
messages Serializable | Iterable[Serializable] A single A2UI message/envelope, or an iterable of them.

Returns: str — A JSONL string; each line is a complete, parseable A2UI v1.0 envelope.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally