Redact String • AI Agent SDK

redact_string: Redact potential secrets from a string.

redact_string

Function

</div>

This function is defined in the redact module.

Redact potential secrets from a string.

This is a best-effort function that looks for common patterns like “api_key=xxx” or “password: xxx” in strings, plus secrets carried in URLs (`scheme://user:pass@host userinfo, ?token=xxx query params and /bot&lt;id&gt;:&lt;token&gt;/` path segments).

Signature

python
def redact_string(text: str, enabled: bool) -> str

Parameters

ParamField str

String to redact

ParamField bool

If False, returns text unchanged

Returns

ResponseField str

String with potential secrets redacted

Uses

  • _URL_USERINFO_PATTERN.sub
  • _URL_BOT_TOKEN_PATTERN.sub
  • _REDACT_KV_PATTERN.sub

Used By

Source

View on GitHub

praisonaiagents/trace/redact.py at line 233