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<id>:<token>/` path segments).
Signature
def redact_string(text: str, enabled: bool) -> strParameters
ParamField
strString to redact
ParamField
boolIf False, returns text unchanged
Returns
ResponseField
strString with potential secrets redacted
Uses
_URL_USERINFO_PATTERN.sub_URL_BOT_TOKEN_PATTERN.sub_REDACT_KV_PATTERN.sub
Used By
Source
View on GitHubpraisonaiagents/trace/redact.py at line 233