# openhands.sdk.utils

> API reference for openhands.sdk.utils module

Utility functions for the OpenHands SDK.

### deprecated()

Return a decorator that deprecates a callable with explicit metadata.

Use this helper when you can annotate a function, method, or property with
@deprecated(…). It transparently forwards to `deprecation.deprecated()`
while filling in the SDK’s current version metadata unless custom values are
supplied.

### maybe\_truncate()

Truncate the middle of content if it exceeds the specified length.

Keeps the head and tail of the content to preserve context at both ends.
Optionally saves the full content to a file for later investigation.

* Parameters:
  * `content` – The text content to potentially truncate
  * `truncate_after` – Maximum length before truncation. If None, no truncation occurs
  * `truncate_notice` – Notice to insert in the middle when content is truncated
  * `save_dir` – Working directory to save full content file in
  * `tool_prefix` – Prefix for the saved file (e.g., “bash”, “browser”, “editor”)
* Returns:
  Original content if under limit, or truncated content with head and tail
  preserved and reference to saved file if applicable

### sanitize\_openhands\_mentions()

Sanitize @OpenHands mentions in text to prevent self-mention loops.

This function inserts a zero-width joiner (ZWJ) after the @ symbol in
@OpenHands mentions, making them non-clickable in GitHub comments while
preserving readability. The original case of the mention is preserved.

* Parameters:
  `text` – The text to sanitize
* Returns:
  Text with sanitized @OpenHands mentions (e.g., “@OpenHands” -> “@‍OpenHands”)

### Examples

```pycon  theme={null}
>>> sanitize_openhands_mentions("Thanks @OpenHands for the help!")
'Thanks @u200dOpenHands for the help!'
>>> sanitize_openhands_mentions("Check @openhands and @OPENHANDS")
'Check @u200dopenhands and @u200dOPENHANDS'
>>> sanitize_openhands_mentions("No mention here")
'No mention here'
```

### warn\_deprecated()

Emit a deprecation warning for dynamic access to a legacy feature.

Prefer this helper when a decorator is not practical—e.g. attribute accessors,
data migrations, or other runtime paths that must conditionally warn. Provide
explicit version metadata so the SDK reports consistent messages and upgrades
to `deprecation.UnsupportedWarning` after the removal threshold.


---

> To find navigation and other pages in this documentation, fetch the llms.txt file at: https://docs.openhands.dev/llms.txt