fix(redact): safely handle non-string inputs

redact_sensitive_text() now returns early for None and coerces other
non-string values to str before applying regex-based redaction,
preventing TypeErrors in logging/tool-output paths.

Cherry-picked from PR #2369 by aydnOktay.
This commit is contained in:
aydnOktay 2026-03-21 16:55:02 -07:00 committed by Teknium
parent 52dd479214
commit 40c9a13476
No known key found for this signature in database
2 changed files with 11 additions and 0 deletions

View file

@ -100,6 +100,10 @@ def redact_sensitive_text(text: str) -> str:
Safe to call on any string -- non-matching text passes through unchanged.
Disabled when security.redact_secrets is false in config.yaml.
"""
if text is None:
return None
if not isinstance(text, str):
text = str(text)
if not text:
return text
if os.getenv("HERMES_REDACT_SECRETS", "").lower() in ("0", "false", "no", "off"):