Skip to content

API Reference parrot.outputs.a2ui.catalog

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

parrot.outputs.a2ui.catalog

View source

A2UI component catalog — public decorator, lookup, and envelope validation.

Registration pattern mirrors :func:parrot.outputs.formats.register_renderer (module-level registry dict + decorator that inserts and returns the class), with the added registration-time enforcement of the mandatory lower() contract.

A registrable component class MUST:

  • implement a callable lower(self, component, data_model) -> BasicTree (pure and deterministic — golden-file tested in Module 3), UNLESS it registers with is_primitive=True (the 18 official Basic Catalog primitives, TASK-2536, which ARE the lowering target); and
  • optionally expose class attributes SCHEMA (dict) and INSTRUCTIONS (str), which the decorator folds into the component's :class:ComponentDefinition.

v1.0 catalog resolution (spec §2 G2): a component without an explicit catalogId resolves against its surface's default catalogId (:func:resolve_catalog). The Parrot catalog (:data:DEFAULT_CATALOG_ID) $ref-includes the official Basic Catalog by design, so a bare component name ("Text", "Button", ...) resolves under either — until TASK-2539 migrates the Parrot catalog's own components into the Python registry, the Basic Catalog's 18 names are checked directly against the vendored catalog.json (the source of truth), not the (currently basic-empty) Python registry.

Alias BasicNode

Re-exported from parrot.outputs.a2ui.catalog.base.BasicNode.

Alias BasicTree

Re-exported from parrot.outputs.a2ui.catalog.base.BasicTree.

Alias CatalogError

Re-exported from parrot.outputs.a2ui.catalog.base.CatalogError.

Alias CatalogValidationError

Re-exported from parrot.outputs.a2ui.catalog.base.CatalogValidationError.

Alias ComponentContractError

Re-exported from parrot.outputs.a2ui.catalog.base.ComponentContractError.

Alias ComponentDefinition

Re-exported from parrot.outputs.a2ui.catalog.base.ComponentDefinition.

Alias DEFAULT_CATALOG_ID

Re-exported from parrot.outputs.a2ui.catalog.base.DEFAULT_CATALOG_ID.

Alias FunctionDefinition

Re-exported from parrot.outputs.a2ui.catalog.base.FunctionDefinition.

Alias ProducerOrigin

Re-exported from parrot.outputs.a2ui.catalog.base.ProducerOrigin.

Alias RegisteredComponent

Re-exported from parrot.outputs.a2ui.catalog.base.RegisteredComponent.

Function catalog_header_instructions

Return catalog_id's own header-level instructions block, if any.

Unlike a component's per-name instructions (folded into :func:catalog_instructions as "<name>: <instructions>" lines), a catalog HEADER is guidance that applies to the whole catalog regardless of which (or how many) of its components are registered — e.g. the viz-core catalog's nine guideline rules (FEAT-529 Module 0). The Parrot and Basic catalogs have no header today.

catalog_header_instructions(catalog_id: str) -> str | None

Parameter Type Default Description
catalog_id str The catalog id.

Returns: str | None — The header text, or None if that catalog declares no header.

Function catalog_instructions

Aggregate registered components' embedded instructions for the LLM producer.

catalog_instructions(catalog_ids: Sequence[str] | None = None) -> str

Parameter Type Default Description
catalog_ids Sequence[str] | None None When given, scopes the aggregate to only these catalogs: each catalog's own header block (:func:catalog_header_instructions, if any) followed by "<name>: <instructions>" lines for components registered under one of these ids. None (default) aggregates every registered catalog (today's behavior), prefixed by the header of every catalog that declares one.

Returns: str — A newline-joined instructions block.

Function get_component

Return the registered component for name.

get_component(name: str, catalog_id: str | None = None) -> RegisteredComponent

Parameter Type Default Description
name str The component name.
catalog_id str | None None When given, an exact (catalog_id, name) lookup. When omitted (the default — every pre-FEAT-529 call site), resolves to the unique catalog registering name; if more than one catalog does, raises :class:CatalogError naming the candidates (FEAT-529 Module 0 — no name is ambiguous today; the a2ui-viz-core-charts sibling spec is expected to introduce the first one, at which point its call sites must pass catalog_id explicitly).

Returns: RegisteredComponent

Raises:

  • KeyError — If name is not registered under catalog_id (when given), or not registered under ANY catalog (when omitted).
  • CatalogError — If catalog_id is omitted and name is registered under more than one catalog.

Function get_function

Return the registered function definition for name.

get_function(name: str) -> FunctionDefinition

Parameter Type Default Description
name str

Returns: FunctionDefinition

Raises:

  • KeyError — If name is not registered.

Function list_components

Return the definitions of registered components (name-sorted).

list_components(catalog_id: str | None = None) -> list[ComponentDefinition]

Parameter Type Default Description
catalog_id str | None None When given, only components registered under this catalog. None (default) returns every registered component across every catalog (today's behavior, preserved).

Returns: list[ComponentDefinition]

Function list_functions

Return all registered function definitions (name-sorted).

list_functions() -> list[FunctionDefinition]

Returns: list[FunctionDefinition]

Function register_component

Register a catalog component under name.

Enforces the mandatory lowering contract at registration time: a class without a callable lower() cannot register (raises :class:ComponentContractError) UNLESS is_primitive=True (spec G4).

register_component(name: str, *, requires_actions: bool = False, catalog_id: str = DEFAULT_CATALOG_ID, is_primitive: bool = False, allowed_parents: list[str] | None = None, allowed_children: list[str] | None = None, tool_only: bool = False) -> Callable[[type], type]

Parameter Type Default Description
name str The component type name used in envelopes (e.g. "Chart").
requires_actions bool False Marks the component as action-bearing (D10b). LLM-produced envelopes containing it are rejected by :func:validate_envelope.
catalog_id str DEFAULT_CATALOG_ID Owning catalog id; defaults to the Parrot custom catalog.
is_primitive bool False True for an official Basic Catalog primitive — no lower() is required.
allowed_parents list[str] | None None If set, restricts which component types this one may appear under.
allowed_children list[str] | None None If set, restricts which component types this one may contain as child/children.
tool_only bool False Marks the component as tool-only (FEAT-527). LLM-produced envelopes containing it are rejected by :func:validate_envelope (same gate mechanism as requires_actions).

Returns: Callable[[type], type] — The class decorator.

Raises:

  • ComponentContractError — If the decorated class lacks a callable lower() and is not registered with is_primitive=True.
  • CatalogError — If (catalog_id, name) is already registered to a DIFFERENT class (FEAT-529 Module 0 — the SAME name in a DIFFERENT catalog is allowed and does not raise; re-registering the identical (catalog_id, name, cls) triple is a no-op, preserving the Basic Catalog's idempotent re-registration pattern, e.g. basic_components() calling _register_primitives() on every invocation).

Function register_function

Register a catalog function definition (primarily the Basic Catalog's 14).

register_function(definition: FunctionDefinition) -> None

Parameter Type Default Description
definition FunctionDefinition The function's :class:FunctionDefinition.

Function resolve_catalog

Resolve the effective catalog id for a component (spec §2 G2).

Precedence: the component's own catalogId wins; otherwise the surface's default catalogId applies.

resolve_catalog(component_catalog_id: str | None, surface_catalog_id: str | None) -> str

Parameter Type Default Description
component_catalog_id str | None The component's own catalogId, if any.
surface_catalog_id str | None The surface's default catalogId, if any.

Returns: str — The resolved catalog id.

Raises:

  • CatalogValidationError — (code CATALOG_UNRESOLVED) if neither is set.

Function unregister_component

Remove a component from the catalog (primarily for test isolation).

unregister_component(name: str, catalog_id: str = DEFAULT_CATALOG_ID) -> None

Parameter Type Default Description
name str The component name.
catalog_id str DEFAULT_CATALOG_ID The catalog it was registered under. Defaults to the Parrot catalog (matches :func:register_component's default), so existing bare unregister_component(name) call sites keep working unchanged.

Function validate_envelope

Validate a v1.0 envelope's components against the catalog + structure rules.

Reports ALL problems found (not just the first), so a producer's retry loop can re-prompt with full error context (spec §7).

Checks:

  • Every component's catalogId resolves (:func:resolve_catalog) and names a known component (UNKNOWN_COMPONENT/CATALOG_UNRESOLVED).
  • Exactly one component has id == "root" (MISSING_ROOT).
  • No two components share an id (DUPLICATE_ID).
  • Every child/children reference points at an existing id (DANGLING_CHILD).
  • allowed_parents/allowed_children (when declared) are respected (UNALLOWED_PARENT/UNALLOWED_CHILD).
  • For origin=LLM, no component carries a non-null action OR is registered with requires_actions=True (ACTION_NOT_ALLOWED_FOR_LLM — G2/D10b gate).
  • For origin=LLM, no component is registered with tool_only=True (TOOL_ONLY_NOT_ALLOWED_FOR_LLM — FEAT-527 gate; e.g. HtmlDocument, which carries raw HTML and may only be emitted by deterministic tool producers).
  • For origin=LLM, Chart/DataTable/Map components do not inline a data/datasets row list — only a {"path": ...} data-model binding is allowed (INLINE_DATA_NOT_ALLOWED_FOR_LLM — FEAT-473 G8 gate; origin=TOOL surfaces, e.g. the structured-output adapter, are exempt and may inline rows directly).
  • Surface-level linked data-source descriptors are TOOL-origin only and structurally consistent with bindings, conditions, and transform refs.

validate_envelope(envelope: CreateSurface | UpdateComponents, *, origin: ProducerOrigin = ProducerOrigin.TOOL, surface_catalog_id: str | None = None) -> None

Parameter Type Default Description
envelope CreateSurface | UpdateComponents The :class:CreateSurface/:class:UpdateComponents envelope.
origin ProducerOrigin ProducerOrigin.TOOL Producer origin. The action gate applies ONLY to :attr:ProducerOrigin.LLM envelopes.
surface_catalog_id str | None None The owning surface's default catalogId. If omitted, falls back to envelope.catalog_id when present (CreateSurface carries it; UpdateComponents does not, so callers updating an existing surface should pass it explicitly).

Raises:

  • CatalogValidationError — Aggregating every problem found, via .issues.

Function validate_message

Validate a full v1.0 envelope against the official wire JSON Schemas.

validate_message(message: A2UIAgentMessage | A2UIRendererMessage) -> None

Parameter Type Default Description
message A2UIAgentMessage | A2UIRendererMessage An :class:A2UIAgentMessage or :class:A2UIRendererMessage.

Raises:

  • TypeError — If message is neither envelope type.
  • jsonschema.exceptions.ValidationError — If it does not match the corresponding official schema (agent_to_renderer.json / renderer_to_agent.json).

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