Skip to content

API Reference parrot.outputs.a2ui.builders

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

parrot.outputs.a2ui.builders

View source

Typed deterministic A2UI v1.0 envelope builders (Module 5, decision D1a).

Tools emit A2UI envelopes deterministically from their own data — zero LLM tokens, zero HTML string assembly (spec G2/D1a). These builders construct catalog-valid CreateSurface envelopes from structured Python data and validate them against the catalog allowlist (display-only: requires_actions components are rejected here). Every envelope carries a component with id="root" (spec G6) and top-level props (no properties nesting, no $bind — v1.0 wire throughout).

Pure functions: same input → byte-identical envelope. No clocks, except the snapshot_at fallback of :func:build_linked_surface, no uuids inside the component tree (artifact ids live outside the payload), no network, no LLM.

One-way import rule (G8): this module imports only the a2ui core; never agents, DatasetManager, LLM clients, or the satellite renderers.

Function build_c4_diagram

Build a viz-core Graph envelope with kind="c4".

Thin wrapper over :func:build_graph (groups=boundaries); every validation, layout and origin rule is build_graph's.

build_c4_diagram(*, level: C4Level, nodes: Sequence[GraphNode | dict[str, Any]], edges: Sequence[GraphEdge | dict[str, Any]], boundaries: Sequence[GraphGroup | dict[str, Any]] | None = None, direction: Direction = 'TB', title: str | None = None, accessible_description: str | None = None, size: VizSize = 'tile', layout: GraphLayout | dict[str, Any] | None = None, selection: GraphSelection | dict[str, Any] | None = None, data_binding: str | None = None, data_model: dict[str, Any] | None = None, action: Action | None = None, compute_layout: bool = True, surface_id: str = 'c4-diagram', origin: ProducerOrigin = ProducerOrigin.TOOL) -> CreateSurface

Parameter Type Default Description
level C4Level C4 abstraction level (GraphSpec.level).
nodes Sequence[GraphNode | dict[str, Any]] The diagram's elements.
edges Sequence[GraphEdge | dict[str, Any]] The diagram's relationships.
boundaries Sequence[GraphGroup | dict[str, Any]] | None None Optional C4 boundaries (forwarded as groups).
direction Direction 'TB' GraphSpec.direction.
title str | None None Optional display title.
accessible_description str | None None viz-core common prop.
size VizSize 'tile' viz-core common prop.
layout GraphLayout | dict[str, Any] | None None Optional layout configuration.
selection GraphSelection | dict[str, Any] | None None Optional selection state.
data_binding str | None None Optional data-model pointer.
data_model dict[str, Any] | None None The envelope's dataModel.
action Action | None None Optional component-level action (TOOL origin only).
compute_layout bool True Whether to fill layout.positions.
surface_id str 'c4-diagram' Envelope surface id.
origin ProducerOrigin ProducerOrigin.TOOL Producer origin.

Returns: CreateSurface — The validated :class:~parrot.outputs.a2ui.models.CreateSurface.

Function build_card

Build a display envelope carrying a single InfoCard component.

Public API name is kept as build_card (no breaking change to callers); the emitted component type is InfoCard (spec G9 — Card is now the official Basic Catalog primitive).

build_card(*, title: str, subtitle: str | None = None, body: str | None = None, image: str | None = None, footer: str | None = None, surface_id: str = 'card') -> CreateSurface

Parameter Type Default Description
title str
subtitle str | None None
body str | None None
image str | None None
footer str | None None
surface_id str 'card'

Returns: CreateSurface

Function build_chart

Build a display envelope carrying a single Chart component.

build_chart(*, chart_type: str, x: str, y: Sequence[str], title: str | None = None, data_binding: str | None = None, show_legend: bool = True, surface_id: str = 'chart', data_model: dict[str, Any] | None = None) -> CreateSurface

Parameter Type Default Description
chart_type str
x str
y Sequence[str]
title str | None None
data_binding str | None None
show_legend bool True
surface_id str 'chart'
data_model dict[str, Any] | None None

Returns: CreateSurface

Function build_datatable

Build a display envelope carrying a single DataTable component.

build_datatable(*, columns: Sequence[dict[str, Any]], data_binding: str | None = None, title: str | None = None, total_rows: int | None = None, truncated: bool = False, surface_id: str = 'table', data_model: dict[str, Any] | None = None) -> CreateSurface

Parameter Type Default Description
columns Sequence[dict[str, Any]]
data_binding str | None None
title str | None None
total_rows int | None None
truncated bool False
surface_id str 'table'
data_model dict[str, Any] | None None

Returns: CreateSurface

Function build_graph

Build a display (or action-bearing, TOOL-origin) envelope carrying a single viz-core Graph component.

Unlike every other build_* helper, the emitted Graph component carries its OWN catalogId (:data:~parrot.outputs.a2ui.catalog. viz_core.VIZ_CORE_CATALOG_ID) — the surface's default catalogId stays the Parrot catalog (every public builder does this, spec §2 New Public Interfaces), so Graph resolves under viz-core purely via its own component-level override (spec §2 G2 resolution rule).

build_graph(*, nodes: Sequence[GraphNode | dict[str, Any]], edges: Sequence[GraphEdge | dict[str, Any]], kind: GraphKind = 'flowchart', direction: Direction = 'TB', title: str | None = None, accessible_description: str | None = None, size: VizSize = 'tile', groups: Sequence[GraphGroup | dict[str, Any]] | None = None, layout: GraphLayout | dict[str, Any] | None = None, selection: GraphSelection | dict[str, Any] | None = None, level: C4Level | None = None, data_binding: str | None = None, data_model: dict[str, Any] | None = None, action: Action | None = None, compute_layout: bool = True, surface_id: str = 'graph', origin: ProducerOrigin = ProducerOrigin.TOOL) -> CreateSurface

Parameter Type Default Description
nodes Sequence[GraphNode | dict[str, Any]] The graph's nodes (:class:~parrot.outputs.a2ui.graph. GraphNode instances or equivalent wire-shaped dicts).
edges Sequence[GraphEdge | dict[str, Any]] The graph's edges.
kind GraphKind 'flowchart' GraphSpec.kind.
direction Direction 'TB' GraphSpec.direction.
title str | None None Optional display title.
accessible_description str | None None viz-core common prop; also the lowered fallback's first line and the SVG <title> on static lanes.
size VizSize 'tile' viz-core common prop (layout intent, never pixels).
groups Sequence[GraphGroup | dict[str, Any]] | None None Optional node groupings.
layout GraphLayout | dict[str, Any] | None None Optional layout configuration. When given WITHOUT positions and compute_layout=True (default), positions are filled in (see compute_layout below); its own rank_sep/node_sep (if set) are honoured.
selection GraphSelection | dict[str, Any] | None None Optional selection state.
level C4Level | None None GraphSpec.level — required when kind="c4" (validated by the model).
data_binding str | None None Optional data-model pointer (e.g. "/nodes") — becomes {"path": "/nodes"} on the wire, overlaying each node's state/label/meta at render time.
data_model dict[str, Any] | None None The envelope's dataModel (forwarded to :func:build_surface).
action Action | None None Optional component-level action. TOOL origin (this function's default) may carry one; origin=ProducerOrigin.LLM with an action set is rejected by the existing ACTION_NOT_ALLOWED_FOR_LLM gate (spec G3 — no new gate).
compute_layout bool True When True (default) and the (implicit or explicit) layout engine is "layered" with no positions already given, fills layout.positions via :func:~parrot.outputs.a2ui.graph.compute_positions. False leaves layout.positions absent (renderers without native layout call compute_positions themselves at render time).
surface_id str 'graph' Envelope surface id.
origin ProducerOrigin ProducerOrigin.TOOL Producer origin forwarded to :func:build_surface's :func:~parrot.outputs.a2ui.catalog.validate_envelope call. Defaults to TOOL (unlike every other build_* helper, which default to LLM) since a builder-authored Graph — positions, action — is deterministic tool output by construction (spec's "authoring tiers": the LLM path never calls this builder with positions/action set).

Returns: CreateSurface — The validated :class:~parrot.outputs.a2ui.models.CreateSurface.

Function build_html_document

Build a tool-only display envelope carrying a single HtmlDocument component.

Wraps a TRUSTED, already-rendered HTML document (e.g. the Jinja render_template lane, FEAT-527 spec G5) as an opaque A2UI surface. Always emitted with origin=ProducerOrigin.TOOL — HtmlDocument is registered tool_only=True (TASK-2862) and an LLM-origin envelope containing it fails :func:~parrot.outputs.a2ui.catalog.validate_envelope.

build_html_document(*, title: str, html: str | None = None, src_url: str | None = None, theme: str | None = None, surface_id: str = 'html-document', metadata: ComponentMetadata | None = None) -> CreateSurface

Parameter Type Default Description
title str Document title.
html str | None None Trusted, fully rendered HTML (inline when < 50 KB). Exactly one of html/src_url must be given.
src_url str | None None Signed artifact URL when the document is too large to inline.
theme str | None None Optional theme hint.
surface_id str 'html-document' Envelope surface id.
metadata ComponentMetadata | None None Optional component-level metadata (e.g. carrying extensions.parrot_optional) forwarded to the underlying build_surface call and attached to the root component.

Returns: CreateSurface — The validated CreateSurface.

Raises:

  • ValueError — If neither or both of html/src_url are given.

Function build_infographic

Build a display envelope carrying a single Infographic composite component.

sections is a list of {"heading": ..., "text"?: ..., "components"?: [...]} dicts (nested components are {"component": name, "properties": {...}}).

build_infographic(*, title: str, sections: Sequence[dict[str, Any]], subtitle: str | None = None, theme: str | None = None, surface_id: str = 'infographic', data_model: dict[str, Any] | None = None, metadata: ComponentMetadata | None = None) -> CreateSurface

Parameter Type Default Description
title str
sections Sequence[dict[str, Any]]
subtitle str | None None
theme str | None None
surface_id str 'infographic'
data_model dict[str, Any] | None None
metadata ComponentMetadata | None None Optional component-level metadata (e.g. carrying extensions.parrot_optional) forwarded to the underlying build_surface call and attached to the root component (FEAT-499).

Returns: CreateSurface

Function build_kpicard

Build a display envelope carrying a single KPICard component.

build_kpicard(*, label: str, value: Any, unit: str | None = None, delta: Any = None, trend: str | None = None, surface_id: str = 'kpi') -> CreateSurface

Parameter Type Default Description
label str
value Any
unit str | None None
delta Any None
trend str | None None
surface_id str 'kpi'

Returns: CreateSurface

Function build_linked_surface

Build a TOOL-origin linked CreateSurface (FEAT-598 M4; linked dashboards).

Axis props are validated against fetched frames — frames must carry one frame per source, derived views included (the executor computes them). When snapshot is false, every source still receives an empty rows collection so bindings resolve. inline embeds extra data-model roots (dataModel[key] = {"rows": rows}) that carry no descriptor: widgets whose data is baked into the dashboard; their axes are validated too.

build_linked_surface(components: Sequence[dict[str, Any]], sources: Mapping[str, 'LinkedSource'], frames: Mapping[str, 'pd.DataFrame'], *, surface_id: str, snapshot: bool = True, max_snapshot_rows: int = 500, catalog_id: str = DEFAULT_CATALOG_ID, inline: Mapping[str, Sequence[Mapping[str, Any]]] | None = None) -> CreateSurface

Parameter Type Default Description
components Sequence[dict[str, Any]]
sources Mapping[str, 'LinkedSource']
frames Mapping[str, 'pd.DataFrame']
surface_id str
snapshot bool True
max_snapshot_rows int 500
catalog_id str DEFAULT_CATALOG_ID
inline Mapping[str, Sequence[Mapping[str, Any]]] | None None

Returns: CreateSurface

Raises:

  • ValueError — A bound axis is missing, non-numeric, has no frame, or an inline key collides with a source.
  • CatalogValidationError — The generated envelope fails TOOL-origin validation.

Function build_map

Build a display envelope carrying a single Map component.

Mirrors :func:build_chart/:func:build_datatable. layers is a sequence of MapLayer-shaped dicts (camelCase props: layer, columns, tooltipTemplate, labelField, dataShape, totalCount, capped, geodesic, markerColor).

build_map(*, layers: Sequence[dict[str, Any]], viewport: dict[str, Any] | None = None, base_layer: str | None = None, title: str | None = None, description: str | None = None, query: dict[str, Any] | None = None, data_model: dict[str, Any] | None = None, surface_id: str = 'map') -> CreateSurface

Parameter Type Default Description
layers Sequence[dict[str, Any]]
viewport dict[str, Any] | None None
base_layer str | None None
title str | None None
description str | None None
query dict[str, Any] | None None
data_model dict[str, Any] | None None
surface_id str 'map'

Returns: CreateSurface

Function build_mermaid_diagram

Build a validated single-component MermaidDiagram CreateSurface (FEAT-753).

Normalizes source first (directives stripped, theme lifted — an explicit theme wins), fills diagramType from :func:detect_diagram_type unless given, then delegates to :func:build_surface. Pure: same input -> byte-identical envelope.

build_mermaid_diagram(*, source: str, title: str | None = None, caption: str | None = None, theme: str | None = None, accessible_description: str | None = None, diagram_type: str | None = None, surface_id: str = 'mermaid-diagram', origin: ProducerOrigin = ProducerOrigin.TOOL, metadata: ComponentMetadata | None = None) -> CreateSurface

Parameter Type Default Description
source str Mermaid source.
title str | None None Optional title.
caption str | None None Optional caption.
theme str | None None Optional theme hint (default/neutral/dark/forest/base).
accessible_description str | None None One-sentence screen-reader summary.
diagram_type str | None None Declared type; a mismatch with the detected one fails validation.
surface_id str 'mermaid-diagram' Envelope surface id.
origin ProducerOrigin ProducerOrigin.TOOL Producer origin (default TOOL; pass ProducerOrigin.LLM to apply the LLM gates).
metadata ComponentMetadata | None None Optional component-level metadata forwarded to build_surface.

Returns: CreateSurface — The validated CreateSurface.

Raises:

  • CatalogValidationError — size cap, unsafe statement, or declared diagram_type mismatch.

Function build_surface

Build and validate a single-component display CreateSurface.

Display-only by default (origin=LLM): the envelope is validated with LLM-origin semantics so any requires_actions/action-bearing component, any unknown component, and (FEAT-473 G8) any inlined data/ datasets row list on a Chart/DataTable/Map is rejected. Pass origin=ProducerOrigin.TOOL for deterministic tool-built surfaces (e.g. the FEAT-473 structured-output adapter), which MAY inline rows directly. component_id defaults to "root" so the envelope satisfies the v1.0 wire's root requirement (spec G6) out of the box.

build_surface(component: str, properties: dict[str, Any], *, surface_id: str, component_id: str = _ROOT_COMPONENT_ID, data_model: dict[str, Any] | None = None, origin: ProducerOrigin = ProducerOrigin.LLM, metadata: ComponentMetadata | None = None, surface_metadata: SurfaceMetadata | None = None) -> CreateSurface

Parameter Type Default Description
component str
properties dict[str, Any]
surface_id str
component_id str _ROOT_COMPONENT_ID
data_model dict[str, Any] | None None
origin ProducerOrigin ProducerOrigin.LLM
metadata ComponentMetadata | None None Optional component-level metadata (e.g. carrying extensions.parrot_optional) to attach to the root component (FEAT-499). Wins over any "metadata" key inside properties. Omitted entirely (no key emitted) when None.
surface_metadata SurfaceMetadata | None None Optional SURFACE-level metadata (FEAT-598) set on CreateSurface.metadata; independent of the root component's metadata.

Returns: CreateSurface

Raises:

  • CatalogValidationError — If the component is unknown, action-bearing (LLM origin), or inlines rows on a structured component (LLM origin).

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