Integrate Guardrails into Your Application#
The NeMo Guardrails library provides the following tools to integrate guardrails into your applications.
Use the NeMo Guardrails Python SDK to add guardrails directly into your Python application.
from nemoguardrails import LLMRails, RailsConfig config = RailsConfig.from_path("path/to/config") rails = LLMRails(config) # Use in your application response = rails.generate(messages=[...])
Use the NeMo Guardrails LangChain integration capabilities to wrap guardrails around LangChain chains or use chains within guardrails.
from nemoguardrails.integrations.langchain.runnable_rails import RunnableRails guardrails = RunnableRails(config) chain_with_guardrails = prompt | guardrails | model | output_parser
For more information, refer to the LangChain Integration Guide.
Integrate the NeMo Guardrails API server into your application to add protection to applications in any programming language.
nemoguardrails server --config path/to/configs
You can then use the API server in your application by sending requests to the server’s endpoint.
curl -X POST http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "config_id": "content_safety", "messages": [{"role": "user", "content": "Hello!"}] }'
For more information, refer to Use the Guardrails API Server.
Use the NeMo Guardrails Docker deployment capabilities to deploy guardrails as a containerized service. For more information, refer to Deploy NeMo Guardrails Library with Docker.
For more examples and detailed integration patterns, refer to the examples directory in the NeMo Guardrails GitHub repository.