Skip to content

API Reference parrot.security.redaction

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

parrot.security.redaction

View source

Utilities for redacting secrets before data leaves trusted process memory.

Provides both legacy flat-marker helpers (redact_text / redact_secrets) for backward compatibility and the policy-driven OutputScrubber introduced in FEAT-252 (TASK-1612).

Class OutputScrubber

Policy-driven output scrubber for tool results and egress text.

Wraps the existing redact_text/redact_secrets logic and adds:

  • Reason-tagged redaction markers (***REDACTED:env_dump***, …).
  • Idempotency: re-scrubbing an already-scrubbed value is a no-op.
  • Audit logging: tag + tool name only — the secret value is never logged.
  • Allowlist awareness: callers can exempt known-safe substrings.
  • Recursive structure traversal (dict / list / tuple / str).
Parameter Type Default Description
policy Optional[ScrubPolicy] None The scrub policy to apply. Defaults to ScrubPolicy().
tool_name str 'unknown' Hint used in audit logs. Can be updated per-call via scrub(value, tool_name=...).

Method OutputScrubber.scrub

Recursively scrub value, returning a sanitised copy.

The operation is idempotent: scrub(scrub(x)) == scrub(x).

scrub(value: Any, tool_name: Optional[str] = None) -> Any

Parameter Type Default Description
value Any The value to scrub (str, dict, list, tuple, or other).
tool_name Optional[str] None Override the instance-level tool_name for this call.

Returns: Any — Sanitised copy. Non-string/collection scalars are returned as-is.

Attribute REDACTION_MARKER

Class ScrubPolicy

Policy controlling OutputScrubber behaviour.

Parameter Type Default Description
reason_tags bool True
audit_log bool True
allowlist FrozenSet[str] frozenset()
max_output_bytes int 1048576

Fields:

Field Type Default Description
reason_tags bool True Emit reason-tagged markers (***REDACTED:<reason>***) instead of the plain [REDACTED] sentinel.
audit_log bool True Record matched tag + tool name (never the secret value) via logging.getLogger(__name__).
allowlist FrozenSet[str] field(default_factory=frozenset) Context allowlist — strings matching any of these exact substrings are left un-scrubbed (e.g. a ticket body containing the literal text token= as documentation).
max_output_bytes int 1048576 Inputs larger than this are scrubbed wholesale rather than per-pattern (defence-in-depth for giant blobs).

Function looks_sensitive_key

Return True when a mapping key/name likely denotes a secret.

looks_sensitive_key(key: Any) -> bool

Parameter Type Default Description
key Any

Returns: bool

Function redact_secrets

Recursively redact secret-like values from JSON-ish structures.

redact_secrets(value: Any) -> Any

Parameter Type Default Description
value Any

Returns: Any

Function redact_text

Redact common secret assignments and token-like values in text.

redact_text(text: str) -> str

Parameter Type Default Description
text str

Returns: str

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