nemoguardrails.llm.filters
Module Contents
Functions
API
Returns the previous lines, skipping comments.
Copy messages and replace user content with the input-rail event history.
Align user turns from the end so a message suffix can use a longer cached event history. Retain a placeholder for blocked turns to preserve alignment, and ignore synthetic user events used to resume tool-result generation. The caller’s message dictionaries are not modified.
Copy messages with tool results approved or rewritten by tool-result rails.
Track each ToolMessage occurrence separately, since later turns may reuse a tool_call_id. Validation updates only the occurrences in its current batch; unapproved results retain a blocked-result placeholder. Match messages from the end so a prompt suffix can use a longer event history. Unchecked results retain their content, and caller messages and events are not modified.
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 …”
Filter that turns an array of events into a colang history.
Filter that turns an array of events into a colang history.
Filter that given a conversation, returns a list of events.
Returns the first n turns from a given colang history.
Indents the provided text with the provided number of spaces.
Returns the last n turns from a given colang history.
Filters that given a history in colang format, removes all texts.
Convert events to chat messages with native assistant tool calls and tool results.
Properly handles multimodal content by preserving the structure when the content is in the format of a Message object with potential image_url content. Synthetic user events that resume tool generation are omitted, and tool-result rail updates are applied before returning the messages.
Filter that given a history in colang format, returns all messages.
Filter that given a history in colang 2.0 format, returns all messages.
Filter that turns an array of events into a sequence of user/assistant messages.
The output will look like:
For multimodal content, it extracts text content and indicates if there were images. Tool calls and rail-processed results are serialized as labeled JSON lines; synthetic user events that resume tool generation are omitted.
Filter that given a history in colang format, returns a verbose version of the history.