> 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.v2_x.generation

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

## Module Contents

### Classes

| Name                                                                                               | Description                                             |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| [`LLMGenerationActionsV2dotx`](#nemoguardrails-actions-v2_x-generation-LLMGenerationActionsV2dotx) | Adapted version of LLMGenerationActions for Colang 2.x. |

### Functions

| Name                                                                                                 | Description                                   |
| ---------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| [`_remove_leading_empty_lines`](#nemoguardrails-actions-v2_x-generation-_remove_leading_empty_lines) | Remove the leading empty lines if they exist. |

### Data

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

### API

```python
class nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx()
```

**Bases:** [LLMGenerationActions](/guardrails-python-sdk/nemoguardrails/actions/llm/generation#nemoguardrails-actions-llm-generation-LLMGenerationActions)

Adapted version of LLMGenerationActions for Colang 2.x.

It overrides some methods.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._collect_user_intent_and_examples(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    user_action: str,
    max_example_flows: int
) -> typing.Tuple[typing.List[str], str, bool]
```

async

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._ensure_flows_index()
```

async

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._ensure_instruction_flows_index()
```

async

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._init_colang_flows_index(
    flows: typing.List[str]
) -> typing.Optional[nemoguardrails.embeddings.index.EmbeddingsIndex]
```

async

Initialize an index with colang flows.

The flows are expected to have full definition.

Args
flows: The list of flows, i.e. the flow definition from the source code.

Returns
An initialized index.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._init_flows_index() -> None
```

async

Initializes the index of flows.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.check_for_active_flow_finished_match(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    event_name: str,
    arguments: typing.Any = {}
) -> bool
```

async

Return True if there is a flow waiting for the provided event name and parameters.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.check_if_flow_defined(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    flow_id: str
) -> bool
```

async

Return True if a flow with the provided flow\_id is defined.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.check_if_flow_exists(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    flow_id: str
) -> bool
```

async

Return True if a flow with the provided flow\_id exists.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.create_flow(
    events: typing.List[dict],
    name: str,
    body: str,
    decorators: typing.Optional[str] = None
) -> dict
```

async

Create a new flow during runtime.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    events: typing.List[dict],
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None,
    flow_id: typing.Optional[str] = None
) -> dict
```

async

Generate the body for a flow.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow_continuation(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    events: typing.List[dict],
    temperature: typing.Optional[float] = None,
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> dict
```

async

Generate a continuation for the flow representing the current conversation.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow_from_instructions(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    instructions: str,
    events: typing.List[dict],
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> dict
```

async

Generate a flow from the provided instructions.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow_from_name(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    name: str,
    events: typing.List[dict],
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> str
```

async

Generate a flow from the provided NAME.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_user_intent(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    events: typing.List[dict],
    user_action: str,
    max_example_flows: int = 5,
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> str
```

async

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

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_user_intent_and_bot_action(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    events: typing.List[dict],
    user_action: str,
    max_example_flows: int = 5,
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> dict
```

async

Generate the canonical form for what the user said i.e. user intent and a suitable bot action.

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_value(
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    instructions: str,
    events: typing.List[dict],
    var_name: typing.Optional[str] = None,
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> typing.Any
```

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.
:param llm: Custom llm model to generate\_value

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.get_last_user_message(
    events: typing.List[dict],
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> str
```

async

```python
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.passthrough_llm_action(
    user_message: str,
    state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
    events: typing.List[dict],
    llm: typing.Optional[nemoguardrails.types.LLMModel] = None
)
```

async

```python
nemoguardrails.actions.v2_x.generation._remove_leading_empty_lines(
    s: str
) -> str
```

Remove the leading empty lines if they exist.

A line is considered empty if it has only white spaces.

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