LangChain Integration
There are three main ways in which you can use the NeMo Guardrails library with LangChain:
- Add guardrails to a LangChain agent through the middleware hooks (LangChain v1).
- Add guardrails to a LangChain chain (or
Runnable). - Use a LangChain chain (or
Runnable) inside a guardrails configuration.
Add Guardrails to an Agent
For tool-calling agents built with create_agent, the GuardrailsMiddleware hooks into the agent loop to run safety checks before and after every model call:
For more details, check out the Agent Middleware Guide.
Add Guardrails to a Chain
You can easily add guardrails to a chain using the RunnableRails class:
For more details, check out the RunnableRails Guide and the Chain with Guardrails Guide.
Using a Chain inside Guardrails
To use a chain (or Runnable) inside a guardrails configuration, you can register it as an action.
Once registered, the chain (or Runnable) can be invoked from within a flow:
For a complete example, check out the Runnable as Action Guide.
LangSmith Integration
The NeMo Guardrails library integrates out-of-the-box with LangSmith. To start sending trace information to LangSmith, you have to configure the following environment variables:
For more details on configuring LangSmith check out the LangSmith documentation.