Custom LLM Providers for NeMo Guardrails
This guide covers LangChain-based custom providers (BaseLLM and BaseChatModel) and applies when NEMOGUARDRAILS_LLM_FRAMEWORK=langchain is set. It was the only extension path before 0.22. For the built-in client (the 0.22+ default), implement the LLMModel Protocol instead — see Custom LLM Model.
NeMo Guardrails supports two types of custom LLM providers:
Text Completion Models (BaseLLM)
For models that work with string prompts:
Chat Models (BaseChatModel)
For models that work with message-based conversations:
Using Custom Providers
After registering your custom provider in config.py, use it in config.yml:
Required and Optional Methods
BaseLLM Methods
BaseChatModel Methods
Best Practices
-
Implement async methods: For better performance, always implement
_acall(for BaseLLM) or_agenerate(for BaseChatModel). -
Choose the right base class:
- Use
BaseLLMfor text completion models (prompt → text) - Use
BaseChatModelfor chat models (messages → message)
- Use
-
Import from langchain-core: Always import base classes from
langchain_core.language_models. -
Use correct registration function:
register_llm_provider()forBaseLLMsubclassesregister_chat_provider()forBaseChatModelsubclasses