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:
Example: Database Connection
HTTP Client Lifecycle
The synchronous init function has no asynchronous teardown hook. Do not create a long-lived HTTP client in init unless another application component owns and closes it.
Create a shared canonical client at the surrounding application lifecycle boundary, register it as an action parameter, and close it at shutdown:
Actions that accept http_client: HTTPClient | None = None can use a shared injected client or let http_call create and close a call-scoped fallback. For details, refer to Outbound HTTP in Actions.