Skip to content

API Reference parrot.tools._enhance_html_check

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

parrot.tools._enhance_html_check

View source

HTML validator for LLM-enhanced output (FEAT-197, TASK-1325).

Shared by the infographic enhance pass and the interactive-artifact render pipeline. Uses stdlib html.parser — no new dependencies.

Checks:

  • Every <script src="..."> URL must be in the allowed_bundles whitelist (matching both URL and SRI hash).
  • Every <link rel="stylesheet" href="..."> URL must likewise be whitelisted.
  • Inline <script> blocks (no src) are allowed.
  • Inline <style> blocks are allowed.
  • Inline event handlers (on* attributes), javascript: URIs, <base href>, and <meta http-equiv="refresh"> are always rejected regardless of whitelist.

Raises code='ENHANCE_OUTPUT_INVALID' on any policy violation. The concrete exception type is pluggable via error_cls so callers can keep their own structured error class (InfographicValidationError by default, or e.g. InteractiveValidationError).

Function validate_enhanced_html

Raise ENHANCE_OUTPUT_INVALID if the HTML references disallowed resources.

allowed_bundles must be an iterable of objects with at least::

.scope: str            — "cdn" or "inline"
.url: Optional[str]    — CDN URL (required when scope='cdn')
.sri_hash: Optional[str] — SRI hash (required when scope='cdn')

validate_enhanced_html(html: str, allowed_bundles: Iterable[Any], error_cls: Optional[Callable[[str, Dict[str, Any]], Exception]] = None) -> None

Parameter Type Default Description
html str Full HTML document returned by the LLM enhance step.
allowed_bundles Iterable[Any] Iterable of JSBundle instances from the template.
error_cls Optional[Callable[[str, Dict[str, Any]], Exception]] None Factory (code, detail) -> Exception used to build the raised error. Defaults to InfographicValidationError for backward compatibility; the interactive pipeline passes InteractiveValidationError.

Raises:

  • Exception — Built by error_cls with code ENHANCE_OUTPUT_INVALID on any policy violation.

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