Skip to content

API Reference parrot.outputs.formats.structured_chart

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

parrot.outputs.formats.structured_chart

View source

FEAT-215 (FEAT-223 Module 2 / FEAT-224 Module 2): Structured Chart Output Mode renderer.

Validates LLM-emitted JSON into :class:StructuredChartConfig, sets response.output to the camelCase config dict without the data key, routes data rows to response.data, and leaves response.code untouched (null).

FEAT-223 deterministic refactor: rows come exclusively from the agent's DataFrame (response.data), extracted via :class:StructuredOutputBase._extract_rows. The LLM contributes presentation only (type, x, y, palette, color_by_sign, …); it must NOT emit data rows. If the LLM picks an absent x/y column, the renderer applies a deterministic fallback so the frontend always receives a valid config.

FEAT-224 (Module 2 — G3): The renderer now reads its config from response.output / response.structured_output (where PandasAgent stores the LLM's StructuredChartConfig) rather than from response.code, which is reserved for genuine interpretable Python/TS code. response.code is no longer consulted as a config source; a text-fallback path is retained for any client that sends the raw JSON string in the response body.

Alias BaseChart

Re-exported from parrot.outputs.formats.chart.BaseChart.

Alias OutputMode

Re-exported from parrot.models.outputs.OutputMode.

Attribute STRUCTURED_CHART_SYSTEM_PROMPT

Alias StructuredChartConfig

Re-exported from parrot.models.outputs.StructuredChartConfig.

Class StructuredChartRenderer

Library-agnostic chart renderer for the STRUCTURED_CHART output mode.

Rows come deterministically from the agent's DataFrame injected into response.data (extracted via :meth:StructuredOutputBase._extract_rows). The LLM is responsible for presentation only: chart type, x/y column names, palette, color_by_sign, title, and description. If the LLM picks a column absent from the real data, :meth:_safe_x / :meth:_safe_y apply a deterministic fallback so the frontend never receives an invalid config.

The renderer always:

  • Sets response.data to the canonical list[dict] rows.
  • Returns (out_without_data, wrapped) — the config dict with data excluded, paired with the chart description or prose explanation.
  • Returns (None, error_message) on any unrecoverable error — never raises.

Method StructuredChartRenderer.render

Render a structured chart configuration from the LLM response.

Pipeline (FEAT-224):

  1. Capture explanation from response.response (best-effort).
  2. Parse the LLM-emitted config into :class:StructuredChartConfig (three sources, in priority order): a. response.output — a StructuredChartConfig instance or dict. b. response.structured_output — same types as (a). c. Text fallback via :meth:_extract_json_code on response content. NOTE: response.code is NO LONGER consulted (G3).
  3. Extract real rows deterministically from response.data via :meth:StructuredOutputBase._extract_rows — never from cfg.data.
  4. Serialize rows canonically via :func:canonical_records.
  5. Validate / fallback x/y against the real column set.
  6. Route via :meth:StructuredOutputBase._route_envelope.

On any error: return (None, error_message) — never raise.

render(response: Any, *, environment: str = 'html', **kwargs) -> Tuple[Any, Optional[Any]]

Parameter Type Default Description
response Any An AIMessage-like object with output, structured_output, data, and response attributes. code is ignored as a config source (FEAT-224 G3).
environment str 'html' Rendering environment (unused; kept for protocol compat).
**kwargs {} Forwarded to base class (unused by this renderer).

Returns: Tuple[Any, Optional[Any]] — Tuple[Any, Optional[Any]]:

  • On success: (config_dict_without_data, description_or_explanation)
  • On failure: (None, error_message_str)

Alias StructuredOutputBase

Re-exported from parrot.outputs.formats.structured_base.StructuredOutputBase.

Alias canonical_records

Re-exported from parrot.outputs.formats.table_types.canonical_records.

Attribute logger

Alias register_renderer

Re-exported from parrot.outputs.formats.register_renderer.

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