> 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.actions.llm.generation

A set of actions for generating various types of completions using an LLMs.

## Module Contents

### Classes

| Name                                                                                  | Description                                       |
| ------------------------------------------------------------------------------------- | ------------------------------------------------- |
| [`LLMGenerationActions`](#nemoguardrails-actions-llm-generation-LLMGenerationActions) | A container objects for multiple related actions. |

### Functions

| Name                                                                                        | Description                                                |
| ------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| [`clean_utterance_content`](#nemoguardrails-actions-llm-generation-clean_utterance_content) | Clean an utterance by performing the following operations: |

### Data

[`local_streaming_handlers`](#nemoguardrails-actions-llm-generation-local_streaming_handlers)

[`log`](#nemoguardrails-actions-llm-generation-log)

### API

```python
class nemoguardrails.actions.llm.generation.LLMGenerationActions(
    config: nemoguardrails.rails.llm.config.RailsConfig,
    llm: typing.Optional[nemoguardrails.types.LLMModel],
    llm_task_manager: nemoguardrails.llm.taskmanager.LLMTaskManager,
    get_embedding_search_provider_instance: typing.Callable[[Optional[EmbeddingSearchProvider]], nemoguardrails.embeddings.index.EmbeddingsIndex],
    verbose: bool = False
)
```

A container objects for multiple related actions.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._ensure_bot_message_index()
```

async

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._ensure_flows_index()
```

async

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._ensure_user_message_index()
```

async

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._extract_bot_message_example(
    flow: nemoguardrails.colang.v2_x.lang.colang_ast.Flow
)
```

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._extract_user_message_example(
    flow: nemoguardrails.colang.v2_x.lang.colang_ast.Flow
) -> None
```

Heuristic to extract user message examples from a flow.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._get_general_instructions()
```

Helper to extract the general instruction.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._get_sample_conversation_two_turns()
```

Helper to extract only the two turns from the sample conversation.

This is needed to be included to "seed" the conversation so that the model
can follow the format more easily.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._init_bot_message_index()
```

async

Initializes the index of bot messages.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._init_flows_index()
```

async

Initializes the index of flows.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._init_user_message_index()
```

async

Initializes the index of user messages.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._process_flows()
```

Process the provided flows to extract the user utterance examples.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._render_string(
    template_str: str,
    context: typing.Optional[dict] = None
) -> str
```

Render a string using the provided context information.

**Parameters:**

The string template to render.

The context for rendering.

**Returns:** `str`

The rendered string.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions._search_flows_index(
    text,
    max_results
)
```

async

Search the index of flows.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions.generate_bot_message(
    events: typing.List[dict],
    context: dict,
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
)
```

async

Generate a bot message based on the desired bot intent.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions.generate_intent_steps_message(
    events: typing.List[dict],
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None,
    kb: typing.Optional[nemoguardrails.kb.kb.KnowledgeBase] = None
)
```

async

Generate all three main Guardrails phases with a single LLM call.
The three phases are: user canonical from (user intent), next flow steps (i.e. bot canonical form)
and bot message.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions.generate_next_steps(
    events: typing.List[dict],
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
)
```

async

Generate the next step in the current conversation flow.

Currently, only generates a next step after a user intent.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions.generate_user_intent(
    events: typing.List[dict],
    context: dict,
    config: nemoguardrails.rails.llm.config.RailsConfig,
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None,
    kb: typing.Optional[nemoguardrails.kb.kb.KnowledgeBase] = None
)
```

async

Generate the canonical form for what the user said i.e. user intent.

```python
nemoguardrails.actions.llm.generation.LLMGenerationActions.generate_value(
    instructions: str,
    events: typing.List[dict],
    var_name: typing.Optional[str] = None,
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
)
```

async

Generate a value in the context of the conversation.

:param instructions: The instructions to generate the value.
:param events: The full stream of events so far.
:param var\_name: The name of the variable to generate. If not specified, it will use
the `action_result_key` as the name of the variable.
:param llm: Custom llm model to generate\_value

```python
nemoguardrails.actions.llm.generation.clean_utterance_content(
    utterance: str
) -> str
```

Clean an utterance by performing the following operations:

* replacing "\n" with "
  ".

Args:
utterance (str): The utterance to clean.

Returns:
str: The cleaned utterance.

```python
nemoguardrails.actions.llm.generation.local_streaming_handlers = {}
```

```python
nemoguardrails.actions.llm.generation.log = logging.getLogger(__name__)
```