For the complete documentation index, see llms.txt. This page is also available as Markdown.

Python SDK

Use the Python SDK to enforce guardrails in your applications. Automate safety checks at runtime.

1. Environment Setup

os.environ["RAGAAI_CATALYST_BASE_URL"] = "https://catalyst.raga.ai/api""
os.environ["OPENAI_API_KEY"] = "Your LLM API key"
  • Configures the environment.

    • RAGAAI_CATALYST_BASE_URL: The base URL of the RagaAI Catalyst API for interaction.

    • OPENAI_API_KEY: Key to authenticate OpenAI-based LLM interactions.


2. Initializing the RagaAICatalyst Client

catalyst = RagaAICatalyst(
    access_key="Generate access key form settings",
    secret_key="Generate access key form settings",
)
  • Creates an authenticated client to interact with RagaAI Catalyst.

    • access_key and secret_key: Credentials to access RagaAI Catalyst.


3. Initializing the Guardrails Manager

gdm = GuardrailsManager(project_name="Project Name")
  • Purpose: Sets up a guardrails manager for managing guardrail-related configurations.

    • project_name: Links the guardrails to a specific project .


4. Listing Available Guardrails

  • Retrieves a list of all guardrails configured in the project.

  • Output: A list of guardrails available for use.


5. Listing Fail Conditions

  • Retrieves the conditions under which guardrails will flag a failure.

  • Output: A list of fail conditions (e.g., ALL_FAIL, SOME_FAIL, etc.).


6. Retrieving Deployment IDs

  • Lists all deployment IDs associated with guardrails.

  • Output: A list of deployment IDs, each representing a configuration of guardrails.


7. Fetching Deployment Details

  • Retrieves details of a specific deployment by its ID (17 in this example).

  • Output: Details of the deployment, including associated guardrails and configurations.


8. Adding Guardrails to a Deployment

  • Configures guardrail behavior when conditions fail.

    • guardrailFailConditions: Triggers guardrails when specific conditions are met.

    • deploymentFailCondition: Aggregates multiple failures (ALL_FAIL requires all guardrails to fail).

    • alternateResponse: Fallback response in case of guardrail-triggered failures.

  • Purpose: Defines guardrail configurations.

    • displayName: A user-friendly name for the guardrail.

    • name: The internal name of the guardrail.

    • config: Contains mappings, parameters, and settings for the guardrail's logic.


9. Initializing the GuardExecutor

  • Purpose: Initializes the executor to run evaluations using the deployment id.

    • 17: Deployment ID of the guardrails to apply.

    • field_map: Maps input fields (e.g., context) to expected variables (document).


10. Preparing Input for Evaluation

  • Supplies input for evaluation.

    • message: Represents the user query.

    • prompt_params: Contextual data provided to the model.

    • model_params: Configuration for the LLM response generation.

    • llm_caller: Specifies the API or library to call the LLM.


11. Executing the Guardrails

  • Runs the guardrails evaluation with the given inputs.

Last updated

Was this helpful?