Skip to content

API Reference parrot.tools.infographic_sections

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

parrot.tools.infographic_sections

View source

Section descriptor contract and fail-fast validation gate (FEAT-326, Module 1).

The :class:SectionDescriptor is the machine-enforced spine of the DataAgent Infographic feature: it declares which data fills each section of an infographic template (hero cards, tables, KPIs, …) and is consumed by the data-splice render mode, the authoring mixin, and recipe publication.

Validation is fail-fast and aggregating (spec G-3): rendering must never start with unmet datasets/columns, and any error enumerates every deficit in a single raise — the philosophy of FEAT-324's $bind cross-check.

None of these models store executable code (resolved brainstorm decision): :class:ProvenanceDescriptor records datasets/params/section mapping and snapshot timestamps only.

Class AdhocDatasetAdapter

DatasetManager-shaped adapter over ad-hoc DataFrames.

:func:validate_descriptor_datasets is duck-typed: it only requires a dataset_manager.get_dataset_entry(name) method returning an object with a .columns attribute (or None when the alias is unknown). This adapter satisfies that contract for two ad-hoc sources that are NOT backed by a real DatasetManager:

  • the HTTP render endpoint's {name: DataFrame} payload dict, and
  • the in-process authoring path's REPL namespace (e.g. :class:~parrot.tools.pythonpandas.PythonPandasTool df_locals / locals_dict), from which only pandas.DataFrame values are exposed as datasets — every other local is invisible to the gate and is never executed or evaluated.

When a name exists in both frames and repl_locals, frames takes precedence.

Parameter Type Default Description
frames Optional[Mapping[str, 'pd.DataFrame']] None Explicit {name: DataFrame} mapping. Takes precedence over repl_locals on name collision.
repl_locals Optional[Mapping[str, Any]] None A namespace (e.g. a REPL's locals()) scanned for pandas.DataFrame values; non-DataFrame locals are ignored.

Method AdhocDatasetAdapter.get_dataset_entry

Return a .columns-exposing entry for name, or None.

get_dataset_entry(name: str) -> Optional[_AdhocEntry]

Parameter Type Default Description
name str Dataset alias to resolve.

Returns: Optional[_AdhocEntry] — class:_AdhocEntry wrapping the DataFrame's columns, or None when name is not a known DataFrame in either frames or repl_locals.

Class GapReport

Result of a partial-coverage publish_recipe().

Fields:

Field Type Default Description
gaps List[TransformerGap] The unmapped section builds (recipe is NOT saved when non-empty).
covered List[str] Sections already mappable to registered transformers.

Class ProvenanceDescriptor

Returned with every tier-1 artifact.

Records the datasets/params/section mapping and dataset snapshot timestamps so the artifact can be understood and (for recipes) re-generated. It NEVER stores python source code (resolved brainstorm decision — spec §2 Data Models / §5).

Fields:

Field Type Default Description
descriptor SectionDescriptor The :class:SectionDescriptor that produced the artifact.
dataset_snapshots Dict[str, str] alias -> ISO-8601 snapshot timestamp of the data actually used.
artifact_id str Identifier of the persisted artifact.
tier Literal['one-shot', 'recipe'] "one-shot" (ad-hoc REPL) or "recipe" (published).
recipe_ref Optional[Tuple[str, Optional[str]]] None (name, owner) when tier == "recipe".

Class SectionDescriptor

Machine-enforced contract: template + render mode + sections.

Fields:

Field Type Default Description
template str Registered template name this descriptor targets.
mode Literal['jinja', 'data-splice'] Render mode — "jinja" (context render) or "data-splice" (JSON payload injected into a script-tag marker).
splice_marker_id str 'report-data' HTML id of the <script type="application/json"> marker for data-splice mode (ignored for jinja mode).
sections List[SectionSpec] The ordered list of section specs.
params Dict[str, Any] Free-form descriptor-level parameters (e.g. snapshot date).
dataset_sql Dict[str, str] Optional per-dataset SQL statements, keyed by the dataset alias used in SectionSpec.datasets. Declared at descriptor level (like params) because several sections routinely read the SAME dataset — a single statement is fetched once per replay. publish_recipe threads each entry into the matching DataSourceSpec.sql, which the RecipeRunner passes to DatasetManager.fetch_dataset. REQUIRED for datasets backed by a TableSource: that source rejects a fetch without explicit SQL (no SELECT * on database tables). Statements may contain {param} placeholders resolved from the recipe's params at replay time (the runner rejects unsafe substitutions).
layout Optional[LayoutSpec] None Optional A2UI catalog-component layout (FEAT-420) with $bind pointers into the assembled dataModel. When set, publish_recipe uses it VERBATIM instead of building today's template-based LayoutSpec; absent means unchanged legacy behaviour (spec criterion G-G).
narrative Optional[NarrativeSpec] None Optional declarative narrative step (FEAT-420) — a reference to a skill name, never code (spec G1) — carried through to the published InfographicRecipe unchanged.

Class SectionSpec

One template section and the data that must fill it.

Fields:

Field Type Default Description
name str Human/LLM-facing section identifier (e.g. "hero-cards").
target str Payload JSON-pointer (data-splice mode) or Jinja context key (jinja mode) that receives this section's assembled data.
datasets List[str] Required :class:DatasetManager aliases feeding this section.
columns Dict[str, List[str]] Required columns per dataset alias (alias -> column names).
shape Literal['records', 'scalar', 'mapping', 'table'] Declared shape of the assembled section data.
hint Optional[str] None Optional semantic guidance for the LLM (never enforced).

Class TransformerGap

One unmapped section build found during publish_recipe().

Fields:

Field Type Default Description
section str The section whose build could not be mapped to a registered transformer.
proposed_name str Suggested transformer name for a developer to register.
suggested_source str Transformer source skeleton for HUMAN registration. Never executed (spec G1).

Function validate_descriptor_datasets

Fail-fast check that every section's datasets/columns exist.

Aggregates ALL deficits (dataset-level and column-level, across every section) into a single :class:InfographicValidationError. Rendering must not proceed when this raises.

validate_descriptor_datasets(descriptor: SectionDescriptor, dataset_manager: Any) -> None

Parameter Type Default Description
descriptor SectionDescriptor The descriptor to validate.
dataset_manager Any A :class:DatasetManager-like object exposing get_dataset_entry(name) returning an entry with a columns attribute (or None when the alias is unknown).

Raises:

  • InfographicValidationError — With code "sections_unmet" and a detail dict listing every unmet section.

Function validate_payload_shape

Fail-fast check that an assembled payload matches each section's shape.

Aggregates every mismatch (missing target or wrong shape) into a single :class:InfographicValidationError.

validate_payload_shape(descriptor: SectionDescriptor, payload: Dict[str, Any]) -> None

Parameter Type Default Description
descriptor SectionDescriptor The descriptor whose sections declare the expected shapes.
payload Dict[str, Any] The assembled payload to validate against the descriptor.

Raises:

  • InfographicValidationError — With code "payload_shape_mismatch" and a detail dict listing every offending section.

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