The Init Function for NeMo Guardrails
If config.py contains an init function, it is called during LLMRails initialization. Use it to set up shared resources and register action parameters.
The init function must be synchronous (def init, not async def init). The framework calls it without await, so an async function would silently do nothing.
Any top-level code in config.py runs at import time, before init() is called. This can be used for provider registration that does not require the LLMRails instance.
Basic Usage
Registering Action Parameters
Action parameters registered in config.py are automatically injected into actions that declare them. The runtime matches parameters by name, i.e., the parameter name in the action must match the name used during registration.
config.py:
actions.py:
Built-in Action Parameters
In addition to parameters you register, the runtime automatically injects these built-in parameters into any action that declares them:
See Custom Data for details on accessing config.custom_data inside actions.
Accessing the Configuration
The app parameter provides access to the full configuration: