nemoguardrails.actions.actions

View as Markdown

Module Contents

Classes

NameDescription
ActionMeta-
ActionResultData class representing the result of an action.

Functions

NameDescription
actionDecorator to mark a function or class as an action.

Data

T

API

class nemoguardrails.actions.actions.ActionMeta

Bases: typing.TypedDict

execute_async
bool
is_system_action
bool
name
str
output_mapping
Optional[Callable[[Any], bool]]
class nemoguardrails.actions.actions.ActionResult(
return_value: typing.Optional[typing.Any] = None,
events: typing.Optional[typing.List[dict]] = None,
context_updates: typing.Optional[dict] = dict()
)
Dataclass

Data class representing the result of an action.

context_updates
Optional[dict] = field(default_factory=dict)
events
Optional[List[dict]] = None
return_value
Optional[Any] = None
nemoguardrails.actions.actions.action(
is_system_action: bool = False,
name: typing.Optional[str] = None,
execute_async: bool = False,
output_mapping: typing.Optional[typing.Callable[[Any], bool]] = None
) -> typing.Callable[[T], nemoguardrails.actions.actions.T]

Decorator to mark a function or class as an action.

Parameters:

is_system_action
boolDefaults to False

Flag indicating if the action is a system action.

name
strDefaults to None

The name to associate with the action.

execute_async
boolDefaults to False

Whether the function should be executed in async mode.

output_mapping
Optional[Callable[[Any], bool]]Defaults to None

A function to interpret the action’s result. It accepts the return value (e.g. the first element of a tuple) and return True if the output is not safe.

Returns: Callable[[T], T]

The decorated function or class.

nemoguardrails.actions.actions.T = TypeVar('T', bound=(Union[Callable[..., Any], Type[Any]]))