Skip to main content

Module redact

Module redact 

Source
Expand description

PII / secret redaction helpers.

Replaces common credential patterns in arbitrary strings before they hit logs or error messages. Intentionally conservative — false positives are preferable to leaking a key.

Ported from hermes-agent’s agent/redact.py. MicroClaw uses this in the tracing subscriber layer and at the boundary of tool error messages.

Two rule sets are kept separate:

  • secret rules — high-confidence credential formats (API keys, tokens, private-key material). These have effectively zero false positives, so they are safe to strip from outbound messages via the output guardrail (apply_output_guardrail).
  • PII rules — emails / phone numbers. Useful for log scrubbing, but they must NOT be applied to outbound replies (the bot legitimately sends email addresses and phone numbers to users). They are only used by redact.

Structs§

OutputGuardrailConfig
Output guardrail configuration block.
OutputGuardrailOutcome
Result of applying the output guardrail to a piece of text.

Enums§

OutputGuardrailMode
Output guardrail policy for outbound bot messages.

Constants§

OUTPUT_BLOCKED_NOTICE
Notice substituted for a message that the guardrail blocked.

Functions§

apply_output_guardrail
Apply the output guardrail to outbound text. Returns None when the mode is Off or no credential is detected (the caller delivers text unchanged); returns Some when the text was modified or blocked.
redact
Returns input with known credential and PII patterns replaced. Use for logs and error messages. Allocates a new String only when a match fires.
redact_in_place
redact in-place variant for small buffers.
redact_secrets
Returns input with credential patterns replaced, leaving PII (emails / phone numbers) intact. This is the variant safe to apply to outbound bot messages.
scan_secrets
Returns the distinct credential categories detected in input (e.g. ["openai_key", "github_pat"]), or empty if none.