Configuring 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 or actions.py
Configuration Sections
Define the init() function to initialize resources and register action parameters at startup.
How ToRegister custom text completion and chat models. Use the LLMModel Protocol for the built-in client, or LangChain BaseLLM/BaseChatModel when running with NEMOGUARDRAILS_LLM_FRAMEWORK=langchain.
Implement the LLMModel protocol to connect a non-OpenAI-compatible backend to the NVIDIA NeMo Guardrails library without depending on LangChain.
How ToReplace the LLM framework layer to connect LiteLLM, an in-house orchestrator, or any non-default LLM stack to the NVIDIA NeMo Guardrails library.
How ToRegister custom embedding providers for vector similarity search in the NVIDIA NeMo Guardrails library.
How ToPass and access custom data from config.yml in your initialization code and actions.
How ToRelated Topics
- Custom Actions - Define callable actions in
actions.py - Model Configuration - Configure LLM models in
config.yml