Skip to content

API Reference parrot.tools.infographic_recipes.figure_guard

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

parrot.tools.infographic_recipes.figure_guard

View source

Narrative figure guard — numeric derivability check (FEAT-420 Module 4).

Mechanical fence around the probabilistic narrative layer (spec criterion G-H): after an LLM writes prose over the deterministic narrative_facts (see :mod:parrot.outputs.a2ui.recipes.library), every numeric literal in that prose is checked for derivability from the facts. Any single figure that is NOT derivable discards the entire narrative, not just the offending sentence — a partially-scrubbed paragraph is a new artifact nobody reviewed, and it collapses into the same degraded state as "no narrator" (one fallback path to reason about and test).

Known limitation (accepted by the spec, §7 Known Risks): this guard catches invented figures, not a fluent mis-characterisation of a correct figure — e.g. it cannot tell "EBITDA improved by $42.0K" from "EBITDA worsened by $42.0K" when both prose figures are numerically derivable. This module validates ONLY that every number in the prose traces back to a real fact; it never judges the surrounding sentence.

Pure, dependency-free (stdlib only) so it can be used from a mixin without dragging in a dataframe library or any LLM client.

Function extract_figures

Return every numeric literal appearing in prose, in order.

extract_figures(prose: str) -> list[str]

Parameter Type Default Description
prose str The generated narrative text to scan.

Returns: list[str] — The raw matched substrings (e.g. "$1.23M", "+12.3%", "3"), in the order they appear. Does not mutate prose.

Function figures_are_derivable

Check every figure in prose against the numeric leaves of facts.

figures_are_derivable(prose: str, facts: dict[str, Any]) -> tuple[bool, list[str]]

Parameter Type Default Description
prose str The generated narrative text to validate.
facts dict[str, Any] The deterministic facts (e.g. the narrative_facts transformer's output) every figure must trace back to.

Returns: tuple[bool, list[str]] — (ok, offending). ok is False if ANY figure is not derivable; offending lists those figures (raw, as they appear in prose). Callers MUST discard the WHOLE narrative when ok is False (spec criterion G-H) — this function never edits or mutates prose/facts; it only reports.

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