Custom Initialization#

The config.py file contains initialization code that runs once at startup, before the LLMRails instance is fully initialized. Use it to register custom providers and set up shared resources.

When to Use config.py vs actions.py#

Use Case

File

Reason

Register custom LLM provider

config.py

Must happen before LLMRails initialization

Register custom embedding provider

config.py

Must happen before LLMRails initialization

Initialize database connection

config.py

Shared resource, initialized once

Validate user input

actions.py

Called during request processing

Call external API

actions.py

Called during request processing

Custom guardrail logic

actions.py

Called from Colang flows

Configuration Sections#

The Init Function

Define the init() function to initialize resources and register action parameters at startup.

The Init Function
Custom LLM Providers

Register custom text completion (BaseLLM) and chat models (BaseChatModel) for use with NeMo Guardrails.

Custom LLM Providers
Custom Embedding Providers

Register custom embedding providers for vector similarity search in NeMo Guardrails.

Custom Embedding Providers
Custom Configuration Data

Pass and access custom data from config.yml in your initialization code and actions.

Custom Configuration Data