Skip to content

Latest commit

 

History

History
72 lines (55 loc) · 2.26 KB

File metadata and controls

72 lines (55 loc) · 2.26 KB
title
page nav
Integrate Guardrails into Your Application
Integrate Guardrails
description Add guardrails to existing applications using the Python SDK, LangChain, or HTTP API.
topics
Get Started
AI Safety
tags
Integration
Python
LangChain
SDK
API
content
type difficulty audience
how_to
technical_beginner
engineer
AI Engineer

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 NeMo Guardrails Docker deployment capabilities to deploy guardrails as a containerized service. For more information, refer to .

For more examples and detailed integration patterns, refer to the examples directory in the NeMo Guardrails GitHub repository.