LogoLogo
Slack CommunityCatalyst Login
  • Welcome
  • RagaAI Catalyst
    • User Quickstart
    • Concepts
      • Configure Your API Keys
      • Supported LLMs
        • OpenAI
        • Gemini
        • Azure
        • AWS Bedrock
        • ANTHROPIC
      • Catalyst Access/Secret Keys
      • Enable Custom Gateway
      • Uploading Data
        • Create new project
        • RAG Datset
        • Chat Dataset
          • Prompt Format
        • Logging traces (LlamaIndex, Langchain)
        • Trace Masking Functions
        • Trace Level Metadata
        • Correlating Traces with External IDs
        • Add Dataset
      • Running RagaAI Evals
        • Executing Evaluations
        • Compare Datasets
      • Analysis
      • Embeddings
    • RagaAI Metric Library
      • RAG Metrics
        • Hallucination
        • Faithfulness
        • Response Correctness
        • Response Completeness
        • False Refusal
        • Context Relevancy
        • Context Precision
        • Context Recall
        • PII Detection
        • Toxicity
      • Chat Metrics
        • Agent Quality
        • Instruction Adherence
        • User Chat Quality
      • Text-to-SQL
        • SQL Response Correctness
        • SQL Prompt Ambiguity
        • SQL Context Ambiguity
        • SQL Context Sufficiency
        • SQL Prompt Injection
      • Text Summarization
        • Summary Consistency
        • Summary Relevance
        • Summary Fluency
        • Summary Coherence
        • SummaC
        • QAG Score
        • ROUGE
        • BLEU
        • METEOR
        • BERTScore
      • Information Extraction
        • MINEA
        • Subjective Question Correction
        • Precision@K
        • Chunk Relevance
        • Entity Co-occurrence
        • Fact Entropy
      • Code Generation
        • Functional Correctness
        • ChrF
        • Ruby
        • CodeBLEU
        • Robust Pass@k
        • Robust Drop@k
        • Pass-Ratio@n
      • Marketing Content Evaluation
        • Engagement Score
        • Misattribution
        • Readability
        • Topic Coverage
        • Fabrication
      • Learning Management System
        • Topic Coverage
        • Topic Redundancy
        • Question Redundancy
        • Answer Correctness
        • Source Citability
        • Difficulty Level
      • Additional Metrics
        • Guardrails
          • Anonymize
          • Deanonymize
          • Ban Competitors
          • Ban Substrings
          • Ban Topics
          • Code
          • Invisible Text
          • Language
          • Secret
          • Sentiment
          • Factual Consistency
          • Language Same
          • No Refusal
          • Reading Time
          • Sensitive
          • URL Reachability
          • JSON Verify
        • Vulnerability Scanner
          • Bullying
          • Deadnaming
          • SexualContent
          • Sexualisation
          • SlurUsage
          • Profanity
          • QuackMedicine
          • DAN 11
          • DAN 10
          • DAN 9
          • DAN 8
          • DAN 7
          • DAN 6_2
          • DAN 6_0
          • DUDE
          • STAN
          • DAN_JailBreak
          • AntiDAN
          • ChatGPT_Developer_Mode_v2
          • ChatGPT_Developer_Mode_RANTI
          • ChatGPT_Image_Markdown
          • Ablation_Dan_11_0
          • Anthropomorphisation
      • Guardrails
        • Competitor Check
        • Gibberish Check
        • PII
        • Regex Check
        • Response Evaluator
        • Toxicity
        • Unusual Prompt
        • Ban List
        • Detect Drug
        • Detect Redundancy
        • Detect Secrets
        • Financial Tone Check
        • Has Url
        • HTML Sanitisation
        • Live URL
        • Logic Check
        • Politeness Check
        • Profanity Check
        • Quote Price
        • Restrict Topics
        • SQL Predicates Guard
        • Valid CSV
        • Valid JSON
        • Valid Python
        • Valid Range
        • Valid SQL
        • Valid URL
        • Cosine Similarity
        • Honesty Detection
        • Toxicity Hate Speech
    • Prompt Playground
      • Concepts
      • Single-Prompt Playground
      • Multiple Prompt Playground
      • Run Evaluations
      • Using Prompt Slugs with Python SDK
      • Create with AI using Prompt Wizard
      • Prompt Diff View
    • Synthetic Data Generation
    • Gateway
      • Quickstart
    • Guardrails
      • Quickstart
      • Python SDK
    • RagaAI Whitepapers
      • RagaAI RLEF (RAG LLM Evaluation Framework)
    • Agentic Testing
      • Quickstart
      • Concepts
        • Tracing
          • Langgraph (Agentic Tracing)
          • RagaAI Catalyst Tracing Guide for Azure OpenAI Users
        • Dynamic Tracing
        • Application Workflow
      • Create New Dataset
      • Metrics
        • Hallucination
        • Toxicity
        • Honesty
        • Cosine Similarity
      • Compare Traces
      • Compare Experiments
      • Add metrics locally
    • Custom Metric
    • Auto Prompt Optimization
    • Human Feedback & Annotations
      • Thumbs Up/Down
      • Add Metric Corrections
      • Corrections as Few-Shot Examples
      • Tagging
    • On-Premise Deployment
      • Enterprise Deployment Guide for AWS
      • Enterprise Deployment Guide for Azure
      • Evaluation Deployment Guide
        • Evaluation Maintenance Guide
    • Fine Tuning (OpenAI)
    • Integration
    • SDK Release Notes
      • ragaai-catalyst 2.1.7
  • RagaAI Prism
    • Quickstart
    • Sandbox Guide
      • Object Detection
      • LLM Summarization
      • Semantic Segmentation
      • Tabular Data
      • Super Resolution
      • OCR
      • Image Classification
      • Event Detection
    • Test Inventory
      • Object Detection
        • Failure Mode Analysis
        • Model Comparison Test
        • Drift Detection
        • Outlier Detection
        • Data Leakage Test
        • Labelling Quality Test
        • Scenario Imbalance
        • Class Imbalance
        • Active Learning
        • Image Property Drift Detection
      • Large Language Model (LLM)
        • Failure Mode Analysis
      • Semantic Segmentation
        • Failure Mode Analysis
        • Labelling Quality Test
        • Active Learning
        • Drift Detection
        • Class Imbalance
        • Scenario Imbalance
        • Data Leakage Test
        • Outlier Detection
        • Label Drift
        • Semantic Similarity
        • Near Duplicates Detection
        • Cluster Imbalance Test
        • Image Property Drift Detection
        • Spatio-Temporal Drift Detection
        • Spatio-Temporal Failure Mode Analysis
      • Tabular Data
        • Failure Mode Analysis
      • Instance Segmentation
        • Failure Mode Analysis
        • Labelling Quality Test
        • Drift Detection
        • Class Imbalance
        • Scenario Imbalance
        • Label Drift
        • Data Leakage Test
        • Outlier Detection
        • Active Learning
        • Near Duplicates Detection
      • Super Resolution
        • Semantic Similarity
        • Active Learning
        • Near Duplicates Detection
        • Outlier Detection
      • OCR
        • Missing Value Test
        • Outlier Detection
      • Image Classification
        • Failure Mode Analysis
        • Labelling Quality Test
        • Class Imbalance
        • Drift Detection
        • Near Duplicates Test
        • Data Leakage Test
        • Outlier Detection
        • Active Learning
        • Image Property Drift Detection
      • Event Detection
        • Failure Mode Analysis
        • A/B Test
    • Metric Glossary
    • Upload custom model
    • Event Detection
      • Upload Model
      • Generate Inference
      • Run tests
    • On-Premise Deployment
      • Enterprise Deployment Guide for AWS
      • Enterprise Deployment Guide for Azure
  • Support
Powered by GitBook
On this page

Was this helpful?

  1. RagaAI Catalyst
  2. Guardrails

Quickstart

Last updated 5 months ago

Was this helpful?

This guide walks you through the steps to use the Guardrails feature in RagaAI Catalyst to ensure accurate and contextually appropriate LLM outputs.


Step 1: Navigate to Guardrails

  1. From the main menu, select the Guardrails tab.


Step 2: Create a New Deployment

  1. In the Guardrails tab, click on New Deployment.

  2. Provide a name for your deployment in the dialog box that appears and click Create.


Step 3: Select Guardrails in Your Deployment

  1. After creating a deployment, click on it to view and configure.

  2. Click on Add Guardrails and select the guardrails that match your needs. Guardrails you can select include:

    • Context Adherence

    • NSFW Text

    • Bias Detection

    • Prompt Injection, etc.

    (Full list of available guardrails can be found in the here).


Step 4: Configure Actions (Fail Condition and Alternate Response)

  1. In the Actions section, set the Fail Condition. You can choose from:

    • One Fail: Fails if one guardrail fails.

    • All Fail: Fails if all guardrails fail.

    • High Risk Fail: Fails if one high-risk guardrail fails.

    • All High Risk Fail: Fails if all high-risk guardrails fail.

  2. Optionally, provide an Alternate Response that the system should return if the fail condition is triggered.


Step 5: Save Changes

  1. Click Save Changes to apply your configurations. Make sure all selected guardrails and actions are correctly set before saving.


Step 6: Deploy and Retrieve the Code

  1. After saving your deployment, click the Deploy button.

  2. The deployment will generate code that you can paste into your Python environment to execute guardrails programmatically.


Step 7: Example Code to Execute Guardrails

from ragaai_catalyst import GuardExecutor, RagaAICatalyst, GuardrailsManager
import os

os.environ["RAGAAI_CATALYST_BASE_URL"] = "https://catalyst.raga.ai/api"

catalyst = RagaAICatalyst(
    access_key="Generate access key from settings",
    secret_key="Generate secret key from settings",
)

os.environ["OPENAI_API_KEY"] = "Your LLM API key"

gdm = GuardrailsManager(project_name="Project Name")

# Initialise GuardExecutor with required params and Evaluate
executor = GuardExecutor(<Deployment ID>,gdm,field_map={'context':'document'})


message={'role':'user',
         'content':'What is the capital of France?'
        }
prompt_params={'document':"Paris, France's capital, is a major European city and a global center for art, fashion, gastronomy and culture. Its 19th-century cityscape is crisscrossed by wide boulevards and the River Seine"}
model_params = {'temperature':.7,'model':'gpt-4o-mini'}
llm_caller = 'litellm'

executor([message],prompt_params,model_params,llm_caller)

This code applies the guardrails configured in your deployment to evaluate LLM inputs or outputs based on the selected conditions.

1. Environment Setup

import os
os.environ["RAGAAI_CATALYST_BASE_URL"] = "https://catalyst.raga.ai/api"
os.environ["OPENAI_API_KEY"] = "Your LLM API key"
  • Configures the API base URL for RagaAI Catalyst and the OpenAI API key.

  • RAGAAI_CATALYST_BASE_URL: Specifies the endpoint for RagaAI Catalyst API.

  • OPENAI_API_KEY: Authorizes the LLM interactions with OpenAI's API.


2. Initializing RagaAICatalyst

catalyst = RagaAICatalyst(
    access_key="Generate access key from settings",
    secret_key="Generate secret key from settings",
)
  • Authenticates access to RagaAI Catalyst.

  • access_key and secret_key: Credentials to authenticate user.

  • Obtain these keys from the Catalyst dashboard under the "Settings" tab.


3. Creating a GuardrailsManager

gdm = GuardrailsManager(project_name="Project Name")
  • Sets up a guardrails manager for a specific project.

  • project_name: Links the guardrails to a specific project in RagaAI.


4. Initialising the GuardExecutor

executor = GuardExecutor(<Deployment ID>, gdm, field_map={'context': 'document'})
  • Executes guardrails against the LLM's responses.

  • <Deployment ID>: A unique identifier for your guardrails setup. Create this in the Catalyst Guardrails Configuration UI.

  • gdm: Passes the guardrails manager instance.

  • field_map: Maps input fields (context) in your prompt to expected keys in your dataset or document.


5. Defining the Message

message = {
    'role': 'user',
    'content': 'What is the capital of France?'
}
  • Represents the user’s input query for the LLM.

  • role: Defines the role of the message's author (e.g., user).

  • content: The actual query.


6. Providing Prompt Parameters

prompt_params = {
    'document': "Paris, France's capital, is a major European city and a global center for art, fashion, gastronomy and culture. Its 19th-century cityscape is crisscrossed by wide boulevards and the River Seine"
}
  • Supplies additional context for the LLM to generate a response.

  • document: The text or data providing context for the query.


7. Setting Model Parameters

model_params = {
    'temperature': 0.7,
    'model': 'gpt-4o-mini'
}
  • Configures LLM behavior.

  • temperature: Controls randomness in the model’s output (lower is more deterministic, higher is more creative).

  • model: Specifies the model variant to use (e.g., gpt-4o-mini).


8. Specifying the LLM Caller

llm_caller = 'litellm'
  • Indicates the LLM library or API to use for generating the response.

  • litellm: Refers to a lightweight LLM library compatible with RagaAI.


9. Executing the Guardrails

executor([message], prompt_params, model_params, llm_caller)
  • Runs the guardrails evaluation for the user query and context.

  • [message]: A list containing the user query.

  • prompt_params: Context passed to the model.

  • model_params: Configures how the model generates the response.

  • llm_caller: Specifies which LLM API or library to use.