> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/guardrails/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.colang.v1_0.lang.utils

## Module Contents

### Functions

| Name                                                                                  | Description                                                           |
| ------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [`char_split`](#nemoguardrails-colang-v1_0-lang-utils-char_split)                     | Helper method to split a string by a given character.                 |
| [`extract_main_token`](#nemoguardrails-colang-v1_0-lang-utils-extract_main_token)     | Helper to extract the main token from a line                          |
| [`extract_topic_object`](#nemoguardrails-colang-v1_0-lang-utils-extract_topic_object) | Helper to extract the object from the definition of a topic.          |
| [`get_first_key`](#nemoguardrails-colang-v1_0-lang-utils-get_first_key)               | Helper to get the first key, which transpiles correctly.              |
| [`get_numbered_lines`](#nemoguardrails-colang-v1_0-lang-utils-get_numbered_lines)     | Helper to returned numbered lines.                                    |
| [`get_stripped_tokens`](#nemoguardrails-colang-v1_0-lang-utils-get_stripped_tokens)   | -                                                                     |
| [`params_tokenize`](#nemoguardrails-colang-v1_0-lang-utils-params_tokenize)           | Tokenizer specific to the params parsing.                             |
| [`parse_package_name`](#nemoguardrails-colang-v1_0-lang-utils-parse_package_name)     | Helper to extract a normalized package name.                          |
| [`remove_token`](#nemoguardrails-colang-v1_0-lang-utils-remove_token)                 | Helper to remove a token                                              |
| [`split_args`](#nemoguardrails-colang-v1_0-lang-utils-split_args)                     | Split a string that represents arguments for a function.              |
| [`split_max`](#nemoguardrails-colang-v1_0-lang-utils-split_max)                       | Helper to simulate the behavior of .split(..., max\_instances).       |
| [`string_hash`](#nemoguardrails-colang-v1_0-lang-utils-string_hash)                   | A simple string hash with an equivalent implementation in javascript. |
| [`word_split`](#nemoguardrails-colang-v1_0-lang-utils-word_split)                     | A simple logic that splits by word but takes strings into accounts.   |
| [`ws_tokenize`](#nemoguardrails-colang-v1_0-lang-utils-ws_tokenize)                   | Tokenize a text by whitespace and taking strings into account.        |

### API

```python
nemoguardrails.colang.v1_0.lang.utils.char_split(
    text: str,
    c: str,
    ignore_parenthesis = False,
    ignore_strings = False
) -> typing.List[str]
```

Helper method to split a string by a given character.

:param text: The text to split.
:param c: The character to use as the separator
:param ignore\_parenthesis: If set, it will now account for lists
i.e. starting with \[], () or \{}
:param ignore\_strings: If set, it will not take into account strings.

```python
nemoguardrails.colang.v1_0.lang.utils.extract_main_token(
    text: str
)
```

Helper to extract the main token from a line

```python
nemoguardrails.colang.v1_0.lang.utils.extract_topic_object(
    text: typing.Text
) -> typing.Tuple[typing.Text, typing.Optional[typing.Text]]
```

Helper to extract the object from the definition of a topic.

Supported expressions
is\_open\_source
is\_open\_source for @roboself
is\_open\_source for $company
    is_open_source($roboself)
is\_open\_source(@roboself)

```python
nemoguardrails.colang.v1_0.lang.utils.get_first_key(
    d: dict
)
```

Helper to get the first key, which transpiles correctly.

```python
nemoguardrails.colang.v1_0.lang.utils.get_numbered_lines(
    content: str
)
```

Helper to returned numbered lines.

Comments and empty lines are ignored.

```python
nemoguardrails.colang.v1_0.lang.utils.get_stripped_tokens(
    tokens: typing.List[str]
)
```

```python
nemoguardrails.colang.v1_0.lang.utils.params_tokenize(
    text
)
```

Tokenizer specific to the params parsing.

```python
nemoguardrails.colang.v1_0.lang.utils.parse_package_name(
    text
)
```

Helper to extract a normalized package name.

```python
nemoguardrails.colang.v1_0.lang.utils.remove_token(
    token: str,
    line: str
)
```

Helper to remove a token

```python
nemoguardrails.colang.v1_0.lang.utils.split_args(
    args_str: str
) -> typing.List[str]
```

Split a string that represents arguments for a function.

It supports keyword arguments and also correctly handles strings and lists/dicts.

**Parameters:**

The string with the arguments e.g. 'name="John", colors=\["blue", "red"]'

**Returns:** `List[str]`

The string that correspond to each individual argument value.

```python
nemoguardrails.colang.v1_0.lang.utils.split_max(
    text,
    separator,
    max_instances
)
```

Helper to simulate the behavior of .split(..., max\_instances).

This implementation is meant to transpile correctly to the JS>

```python
nemoguardrails.colang.v1_0.lang.utils.string_hash(
    s
)
```

A simple string hash with an equivalent implementation in javascript.

module.exports.string\_hash = function(s)\{
let hash = 0;
if (s.length === 0) return hash;
for (let i = 0; i \< s.length; i++) \{
let char = s.charCodeAt(i);
hash = ((hash\<\<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
if (hash \< 0) hash \*= -1;

return hash.toString(16);
}

```python
nemoguardrails.colang.v1_0.lang.utils.word_split(
    text: str,
    word: str
)
```

A simple logic that splits by word but takes strings into accounts.

```python
nemoguardrails.colang.v1_0.lang.utils.ws_tokenize(
    text
)
```

Tokenize a text by whitespace and taking strings into account.