Creating and Using Stages

Stages can be managed centrally (i.e. registered once and updated dynamically) or locally within the application. Stages consist 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.

All stages must have names and belong to a project. The project ID is required to create a stage. The stage ID is returned when the stage is created and is required to invoke the stage. Optionally, you can provide a description of the stage.

Check out Concepts > Stages for the difference between a Central and a Local stage, and when to use each.

Creating a Stage

To create a stage, you can use the following code snippet:

import galileo_protect as gp

gp.create_stage(name="my first stage", project_id="<project_id>", description="This is my first stage", type="local")  # type can be "central" or "local", default is "local"

If you're using central stages, we recommend including the ruleset definitions during stage creation. This way, you can manage the rulesets centrally and update them without changing the invocation code.

import galileo_protect as gp

gp.create_stage(name="my first stage", project_id="<project_id>", description="This is my first stage", type="central", 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."
            ],
        },
    },
])

If you're using local stages, you can define the rulesets within the gp.invoke() function during the invocation.

Last updated