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§
- Output
Guardrail Config - Output guardrail configuration block.
- Output
Guardrail Outcome - Result of applying the output guardrail to a piece of text.
Enums§
- Output
Guardrail Mode - 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. ReturnsNonewhen the mode isOffor no credential is detected (the caller deliverstextunchanged); returnsSomewhen the text was modified or blocked. - redact
- Returns
inputwith known credential and PII patterns replaced. Use for logs and error messages. Allocates a new String only when a match fires. - redact_
in_ place redactin-place variant for small buffers.- redact_
secrets - Returns
inputwith 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.