| Name | Type | Description |
|---|---|---|
text* | str | Untrusted text to sanitize. |
keep_newlines | bool | Default: FalseWhen |
collapse_whitespace | bool | Default: TrueWhen |
max_length | int | None | Default: None |
Neutralize control characters and deceptive Unicode in untrusted text.
Untrusted strings (MCP server errors, config-file contents, tool output)
can carry ANSI escape sequences, other control characters, or invisible
Unicode that corrupts the terminal, breaks out of a layout, or injects fake
lines into logs and prompts. This first removes the invisible/bidi code
points flagged by strip_dangerous_unicode, then replaces every remaining
Unicode "Other" (control/format) character with a space.
When set, truncate to at most this many characters, replacing the final character with an ellipsis.