> 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 AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.llm.filters

## Module Contents

### Functions

| Name                                                                                   | Description                                                                             |
| -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| [`_previous_line`](#nemoguardrails-llm-filters-_previous_line)                         | Returns the previous lines, skipping comments.                                          |
| [`co_v2`](#nemoguardrails-llm-filters-co_v2)                                           | Creates a history of user messages and bot responses in colang format.                  |
| [`colang`](#nemoguardrails-llm-filters-colang)                                         | Filter that turns an array of events into a colang history.                             |
| [`colang_without_identifiers`](#nemoguardrails-llm-filters-colang_without_identifiers) | Filter that turns an array of events into a colang history.                             |
| [`conversation_to_events`](#nemoguardrails-llm-filters-conversation_to_events)         | Filter that given a conversation, returns a list of events.                             |
| [`first_turns`](#nemoguardrails-llm-filters-first_turns)                               | Returns the first n turns from a given colang history.                                  |
| [`indent`](#nemoguardrails-llm-filters-indent)                                         | Indents the provided text with the provided number of spaces.                           |
| [`last_turns`](#nemoguardrails-llm-filters-last_turns)                                 | Returns the last n turns from a given colang history.                                   |
| [`remove_text_messages`](#nemoguardrails-llm-filters-remove_text_messages)             | Filters that given a history in colang format, removes all texts.                       |
| [`remove_trailing_new_line`](#nemoguardrails-llm-filters-remove_trailing_new_line)     | -                                                                                       |
| [`to_chat_messages`](#nemoguardrails-llm-filters-to_chat_messages)                     | Filter that turns an array of events into a sequence of user/assistant messages.        |
| [`to_intent_messages`](#nemoguardrails-llm-filters-to_intent_messages)                 | -                                                                                       |
| [`to_intent_messages_2`](#nemoguardrails-llm-filters-to_intent_messages_2)             | -                                                                                       |
| [`to_messages`](#nemoguardrails-llm-filters-to_messages)                               | Filter that given a history in colang format, returns all messages.                     |
| [`to_messages_v2`](#nemoguardrails-llm-filters-to_messages_v2)                         | Filter that given a history in colang 2.0 format, returns all messages.                 |
| [`user_assistant_sequence`](#nemoguardrails-llm-filters-user_assistant_sequence)       | Filter that turns an array of events into a sequence of user/assistant messages.        |
| [`verbose_v1`](#nemoguardrails-llm-filters-verbose_v1)                                 | Filter that given a history in colang format, returns a verbose version of the history. |

### API

```python
nemoguardrails.llm.filters._previous_line(
    lines: typing.List[str],
    i: int
)
```

Returns the previous lines, skipping comments.

```python
nemoguardrails.llm.filters.co_v2(
    events: typing.List[dict]
) -> str
```

Creates a history of user messages and bot responses in colang format.

user said "Hi, how are you today?"
bot say "Greetings! I am the official NVIDIA Benefits Ambassador AI bot and I'm here to assist you."
user said "What can you help me with?"
bot say "As an AI, I can provide you with a wide range of services, such as ..."

```python
nemoguardrails.llm.filters.colang(
    events: typing.List[dict]
) -> str
```

Filter that turns an array of events into a colang history.

```python
nemoguardrails.llm.filters.colang_without_identifiers(
    events: typing.List[dict]
) -> str
```

Filter that turns an array of events into a colang history.

```python
nemoguardrails.llm.filters.conversation_to_events(
    conversation: typing.List
) -> typing.List[dict]
```

Filter that given a conversation, returns a list of events.

```python
nemoguardrails.llm.filters.first_turns(
    colang_history: str,
    n: int
) -> str
```

Returns the first n turns from a given colang history.

```python
nemoguardrails.llm.filters.indent(
    text: str,
    n_spaces: int
) -> str
```

Indents the provided text with the provided number of spaces.

```python
nemoguardrails.llm.filters.last_turns(
    colang_history: str,
    n: int
) -> str
```

Returns the last n turns from a given colang history.

```python
nemoguardrails.llm.filters.remove_text_messages(
    colang_history: str
)
```

Filters that given a history in colang format, removes all texts.

```python
nemoguardrails.llm.filters.remove_trailing_new_line(
    s: str
)
```

```python
nemoguardrails.llm.filters.to_chat_messages(
    events: typing.List[dict]
) -> typing.List[dict]
```

Filter that turns an array of events into a sequence of user/assistant messages.

Properly handles multimodal content by preserving the structure when the content
is in the format of a Message object with potential image\_url content.

```python
nemoguardrails.llm.filters.to_intent_messages(
    colang_history: str
) -> typing.List[dict]
```

```python
nemoguardrails.llm.filters.to_intent_messages_2(
    colang_history: str
) -> typing.List[dict]
```

```python
nemoguardrails.llm.filters.to_messages(
    colang_history: str
) -> typing.List[dict]
```

Filter that given a history in colang format, returns all messages.

```python
nemoguardrails.llm.filters.to_messages_v2(
    colang_history: str
) -> typing.List[dict]
```

Filter that given a history in colang 2.0 format, returns all messages.

```python
nemoguardrails.llm.filters.user_assistant_sequence(
    events: typing.List[dict]
) -> str
```

Filter that turns an array of events into a sequence of user/assistant messages.

For multimodal content, it extracts text content and indicates if there were images.

```python
nemoguardrails.llm.filters.verbose_v1(
    colang_history: str
) -> str
```

Filter that given a history in colang format, returns a verbose version of the history.