Getting Started

Why use Galileo Protect?

Galileo Protect acts as an LLM Firewall proactively protecting your system from bad inputs, and your users from bad outputs. It empowers you to harden your GenAI system against malicious activities, such as prompt injections or offensive inputs, and allows you to take control of your application's outputs and avoid hallucinations, data leakage, or off-brand responses.

How to get started with Galileo Protect?

Step 1: Getting your Galileo API key

Please follow the "Getting an API key" section here to get your API key.

Step 2: Install the necessary Python Client

  • Open a Python notebook or the Python environment where you want to install Galileo

  • Install the python client via pip install galileo-protect

  • Next, run the following code to create a project and get project_id and stage_id to set up integration.

import galileo_protect as gp
import os

os.environ['GALILEO_API_KEY']="Your Galileo API key"
os.environ['GALILEO_CONSOLE_URL']="Your Galileo Console Url"

project = gp.create_project('my first protect project')
project_id = project.id

stage = gp.create_stage(name="my first stage", project_id=project_id)
stage_id = stage.id

Step 3: Integrate Galileo Protect with your app

Galileo Protect can be embedded in your production application through gp.invoke() like below:

USER_QUERY = 'What\'s my SSN? Hint: my SSN is 123-45-6789'
MODEL_RESPONSE = 'Your SSN is 123-45-6789' #replace this string with the actual model response

response = gp.invoke(
        payload={"input":USER_QUERY, "output":MODEL_RESPONSE},
        prioritized_rulesets=[
            {
                "rules": [
                    {
                        "metric": "pii",
                        "operator": "contains",
                        "target_value": "ssn",
                    },
                ],
                "action": {
                    "type": "OVERRIDE",
                    "choices": [
                        "Personal Identifiable Information detected in the model output. Sorry, I cannot answer that question."
                    ],
                },
            },
        stage_id=stage_id,
        timeout=10,  # number of seconds for timeout
    )

As part of your invocation config, you'll need to define a set of Rules you want your application to adhere to, and the Actions that should be taken when these rules are broken.

Quick Definitions:

Below are some concepts needed to configure your calls to Galileo Protect:

Project: A project tracks a single-user application, and draws from our existing definitions of controls around projects. A project can contain multiple stages.

Stage: A set of rulesets that are applied during one invocation. A stage can be composed of multiple rulesets, each executed independently and defined as a prioritized list (i.e. order matters). The action for the ruleset with the highest priority is chosen for composing the response. We recommend defining a stage on your user queries and one on your application's output.

Ruleset: A collection of one or more Rules combined with an Action. The Ruleset gets triggered when all of the rules are broken (i.e. all their condition evaluate to True). Only the Action of the highest priority Trigger-ing Ruleset will be executed.

Rule: A condition or rule you never want your application to break. It's comprised of three ingredients: a metric, an operator, and a target value.

Action: User-defined action that is taken as a result of the guardrail execution when the guardrail is triggered.

Check out the next section for more information.

Last updated