Configuring Custom Actions
This section guides you through how to create the actions.py file to define custom Python actions and integrate them into the NeMo Guardrails library.
By configuring custom actions, you can execute Python code within guardrails flows, extending the library with custom logic, external API integrations, and complex validation.
An actions.py file defines custom action functions using the @action decorator. A decorator is a callable that takes a function and returns a new function, usually adding behavior or attaching metadata.
Configuration Sections
The following sections provide detailed documentation for creating and using custom actions:
File Organization
Custom actions can be organized in two ways:
Option 1: Single actions.py file
Option 2: actions/ sub-package
Quick Example
1. Define the Action
Create config/actions.py:
2. Create a Flow Using the Action
Create config/rails/output.co:
3. Configure the Rail
Add to config/config.yml:
For detailed information about each topic, refer to the individual pages linked above.