Skip to content

Galileo Protect Reference

__version__ module-attribute

__version__ = '0.8.0'

OverrideAction

Bases: BaseAction

Parameters:

  • type (Literal[ActionType], default: <ActionType.OVERRIDE: 'OVERRIDE'> ) –
  • choices (Sequence[str]) –

    List of choices to override the response with. If there are multiple choices, one will be chosen at random when applying this action.

type class-attribute instance-attribute

type: Literal[OVERRIDE] = OVERRIDE

choices class-attribute instance-attribute

choices: Sequence[str] = Field(description='List of choices to override the response with. If there are multiple choices, one will be chosen at random when applying this action.', min_length=1)

apply

apply(response: str) -> ActionResult

Parameters:

  • response (str) –

PassthroughAction

Bases: BaseAction

Parameters:

  • type (Literal[ActionType], default: <ActionType.PASSTHROUGH: 'PASSTHROUGH'> ) –

type class-attribute instance-attribute

type: Literal[PASSTHROUGH] = PASSTHROUGH

apply

apply(response: str) -> ActionResult

Parameters:

  • response (str) –

Payload

Bases: BaseModel

Parameters:

  • input (str | None, default: None ) –

    Input text to be processed.

  • output (str | None, default: None ) –

    Output text to be processed.

input class-attribute instance-attribute

input: Optional[str] = Field(default=None, description='Input text to be processed.')

output class-attribute instance-attribute

output: Optional[str] = Field(default=None, description='Output text to be processed.')

text cached property

text: str

ensure_input_or_output

ensure_input_or_output() -> Payload

Request

Bases: BaseModel

Parameters:

  • payload (Payload) –

    Payload to be processed.

  • project_id (Annotated[UUID, UuidVersion] | None, default: None ) –

    Project ID.

  • stage_name (str | None, default: None ) –

    Stage name.

  • stage_id (Annotated[UUID, UuidVersion] | None, default: None ) –

    Stage ID.

  • rulesets (Sequence[Ruleset], default: [] ) –

    Rulesets to be applied to the payload.

  • timeout (float, default: 300.0 ) –

    Optional timeout for the guardrail execution in seconds. This is not the timeout for the request. If not set, a default timeout of 5 minutes will be used.

  • metadata (Dict[str, str] | None, default: None ) –

    Optional additional metadata. This will be echoed back in the response.

  • headers (Dict[str, str] | None, default: None ) –

    Optional additional HTTP headers that should be included in the response.

payload class-attribute instance-attribute

payload: Payload = Field(description='Payload to be processed.')

project_id class-attribute instance-attribute

project_id: Optional[UUID4] = Field(default=None, description='Project ID.', validate_default=True)

stage_name class-attribute instance-attribute

stage_name: Optional[str] = Field(default=None, description='Stage name.', validate_default=True)

stage_id class-attribute instance-attribute

stage_id: Optional[UUID4] = Field(default=None, description='Stage ID.', validate_default=True)

rulesets class-attribute instance-attribute

rulesets: Sequence[Ruleset] = Field(default_factory=list, description='Rulesets to be applied to the payload.', validation_alias='prioritized_rulesets')

timeout class-attribute instance-attribute

timeout: float = Field(default=total_seconds(), description='Optional timeout for the guardrail execution in seconds. This is not the timeout for the request. If not set, a default timeout of 5 minutes will be used.')

metadata class-attribute instance-attribute

metadata: Optional[Dict[str, str]] = Field(default=None, description='Optional additional metadata. This will be echoed back in the response.')

headers class-attribute instance-attribute

headers: Optional[Dict[str, str]] = Field(default=None, description='Optional additional HTTP headers that should be included in the response.')

model_config class-attribute instance-attribute

model_config = ConfigDict(populate_by_name=True)

rules cached property

rules: List[Rule]

metrics cached property

metrics: Set[str]

timeout_ns cached property

timeout_ns: float

project_id_from_env

project_id_from_env(value: Optional[UUID4]) -> Optional[UUID4]

Parameters:

  • value (Optional[UUID4]) –

stage_name_from_env

stage_name_from_env(value: Optional[str]) -> Optional[str]

Parameters:

  • value (Optional[str]) –

stage_id_from_env

stage_id_from_env(value: Optional[UUID4]) -> Optional[UUID4]

Parameters:

  • value (Optional[UUID4]) –

validate_stage

validate_stage() -> Request

Validate that either stage_id or both stage_name and project_id are provided.

Returns:

Raises:

  • ValueError

    If neither stage_id nor both stage_name and project_id are provided.

Response

Bases: BaseModel

Parameters:

  • text (str) –

    Text from the request after processing the rules.

  • status (str | None, default: None ) –

    Status of the request after processing the rules.

text class-attribute instance-attribute

text: str = Field(description='Text from the request after processing the rules.')

status class-attribute instance-attribute

status: Optional[str] = Field(default=None, description='Status of the request after processing the rules.')

model_config class-attribute instance-attribute

model_config = ConfigDict(extra='allow')

Rule

Bases: BaseModel

Parameters:

  • metric (str) –

    Name of the metric.

  • operator (RuleOperator) –

    Operator to use for comparison.

  • target_value (str | float | int | list | None) –

    Value to compare with for this metric (right hand side).

metric class-attribute instance-attribute

metric: str = Field(description='Name of the metric.')

operator class-attribute instance-attribute

operator: RuleOperator = Field(description='Operator to use for comparison.')

target_value class-attribute instance-attribute

target_value: Union[str, float, int, list, None] = Field(description='Value to compare with for this metric (right hand side).')

evaluate

evaluate(value: MetricValueType) -> bool

Parameters:

  • value (MetricValueType) –

RuleMetrics

Bases: str, Enum

input_pii class-attribute instance-attribute

input_pii = 'input_pii'

input_sexist class-attribute instance-attribute

input_sexist = 'input_sexist'

input_tone class-attribute instance-attribute

input_tone = 'input_tone'

input_toxicity class-attribute instance-attribute

input_toxicity = 'input_toxicity'

prompt_injection class-attribute instance-attribute

prompt_injection = 'prompt_injection'

pii class-attribute instance-attribute

pii = 'pii'

sexist class-attribute instance-attribute

sexist = 'sexist'

tone class-attribute instance-attribute

tone = 'tone'

toxicity class-attribute instance-attribute

toxicity = 'toxicity'

RuleOperator

Bases: str, Enum

gt class-attribute instance-attribute

gt = 'gt'

lt class-attribute instance-attribute

lt = 'lt'

gte class-attribute instance-attribute

gte = 'gte'

lte class-attribute instance-attribute

lte = 'lte'

eq class-attribute instance-attribute

eq = 'eq'

neq class-attribute instance-attribute

neq = 'neq'

contains class-attribute instance-attribute

contains = 'contains'

all class-attribute instance-attribute

all = 'all'

any class-attribute instance-attribute

any = 'any'

empty class-attribute instance-attribute

empty = 'empty'

not_empty class-attribute instance-attribute

not_empty = 'not_empty'

Ruleset

Bases: BaseModel

Parameters:

  • rules (Sequence[Rule], default: [] ) –

    List of rules to evaluate. Atleast 1 rule is required.

  • action (OverrideAction | PassthroughAction, default: PassthroughAction(type=<ActionType.PASSTHROUGH: 'PASSTHROUGH'>) ) –

    Action to take if all the rules are met.

  • description (str | None, default: None ) –

    Description of the ruleset.

rules class-attribute instance-attribute

rules: Sequence[Rule] = Field(description='List of rules to evaluate. Atleast 1 rule is required.', default_factory=list, min_length=1)

action class-attribute instance-attribute

action: Action = Field(description='Action to take if all the rules are met.', default_factory=PassthroughAction)

description class-attribute instance-attribute

description: Optional[str] = Field(description='Description of the ruleset.', default=None)

validate_action

validate_action(value: Optional[BaseAction]) -> BaseAction

Parameters:

  • value (Optional[BaseAction]) –

Stage

Bases: BaseModel

Parameters:

  • name (str) –

    Name of the stage. Must be unique within the project.

  • project_id (UUID) –

    ID of the project to which this stage belongs.

  • description (str | None, default: None ) –

    Optional human-readable description of the goals of this guardrail.

  • action (OverrideAction | PassthroughAction, default: PassthroughAction(type=<ActionType.PASSTHROUGH: 'PASSTHROUGH'>) ) –

    An optional action (kill switch) to take that supersedes all ruleset validations.

  • action_enabled (bool, default: False ) –

    Whether the action is enabled. If False, the action will not be applied.

name class-attribute instance-attribute

name: str = Field(description='Name of the stage. Must be unique within the project.')

project_id class-attribute instance-attribute

project_id: UUID4 = Field(description='ID of the project to which this stage belongs.')

description class-attribute instance-attribute

description: Optional[str] = Field(description='Optional human-readable description of the goals of this guardrail.', default=None)

action class-attribute instance-attribute

action: Action = Field(default_factory=PassthroughAction, description='An optional action (kill switch) to take that supersedes all ruleset validations.')

action_enabled class-attribute instance-attribute

action_enabled: bool = Field(description='Whether the action is enabled. If False, the action will not be applied.', default=False)

ProtectParser

Bases: BaseModel

Parameters:

  • chain (Runnable) –

    The chain to trigger if the Protect invocation is not triggered.

  • ignore_trigger (bool, default: False ) –

    Ignore the status of the Protect invocation and always trigger the rest of the chain.

  • echo_output (bool, default: False ) –

    Echo the output of the Protect invocation.

chain class-attribute instance-attribute

chain: Runnable = Field(..., description='The chain to trigger if the Protect invocation is not triggered.')

ignore_trigger class-attribute instance-attribute

ignore_trigger: bool = Field(default=False, description='Ignore the status of the Protect invocation and always trigger the rest of the chain.')

echo_output class-attribute instance-attribute

echo_output: bool = Field(default=False, description='Echo the output of the Protect invocation.')

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

parser

parser(response_raw_json: str) -> str

Parameters:

  • response_raw_json (str) –

ProtectTool

Bases: BaseTool

name class-attribute instance-attribute

name: str = 'GalileoProtect'

description class-attribute instance-attribute

description: str = "Protect your LLM applications from harmful content using Galileo Protect. This tool is a wrapper around Galileo's Protect API, can be used to scan text for harmful content, and can be used to trigger actions based on the results.The tool can be used synchronously or asynchronously, on the input text or output text,and can be configured with a set of rulesets to evaluate on."

args_schema class-attribute instance-attribute

args_schema: Type[BaseModel] = PayloadV1

prioritized_rulesets class-attribute instance-attribute

prioritized_rulesets: Optional[Sequence[Ruleset]] = None

project_id class-attribute instance-attribute

project_id: Optional[UUID4] = None

stage_name class-attribute instance-attribute

stage_name: Optional[str] = None

stage_id class-attribute instance-attribute

stage_id: Optional[UUID4] = None

timeout class-attribute instance-attribute

timeout: float = TIMEOUT

config class-attribute instance-attribute

config: Optional[ProtectConfig] = None

_run

_run(input: Optional[str] = None, output: Optional[str] = None) -> str

Apply the tool synchronously.

We serialize the response to JSON because that's what langchain_core expects for tools.

Parameters:

  • input (Optional[str], default: None ) –
  • output (Optional[str], default: None ) –

_arun async

_arun(input: Optional[str] = None, output: Optional[str] = None) -> str

Apply the tool asynchronously.

We serialize the response to JSON because that's what langchain_core expects for tools.

Parameters:

  • input (Optional[str], default: None ) –
  • output (Optional[str], default: None ) –

is_dependency_available

is_dependency_available(name: str) -> bool

Check if a dependency is available.

Parameters:

  • name (str) –

Parameters:

  • name (str) –

    The name of the dependency to check.

Returns:

  • bool

    True if the dependency is available, False otherwise.

get_project

get_project(project_id: UUID4, config: GalileoConfig) -> ProjectResponse

Parameters:

  • project_id (UUID4) –
  • config (GalileoConfig) –

get_project_from_name

get_project_from_name(project_name: str, config: GalileoConfig, raise_if_missing: bool = True) -> Optional[ProjectResponse]

Parameters:

  • project_name (str) –
  • config (GalileoConfig) –
  • raise_if_missing (bool, default: True ) –

ainvoke async

ainvoke(payload: Payload, prioritized_rulesets: Optional[Sequence[Ruleset]] = None, project_id: Optional[UUID4] = None, stage_name: Optional[str] = None, stage_id: Optional[UUID4] = None, timeout: float = TIMEOUT, metadata: Optional[Dict[str, str]] = None, headers: Optional[Dict[str, str]] = None, config: Optional[ProtectConfig] = None) -> Response

Parameters:

  • payload (Payload) –
  • prioritized_rulesets (Optional[Sequence[Ruleset]], default: None ) –
  • project_id (Optional[UUID4], default: None ) –
  • stage_name (Optional[str], default: None ) –
  • stage_id (Optional[UUID4], default: None ) –
  • timeout (float, default: TIMEOUT ) –
  • metadata (Optional[Dict[str, str]], default: None ) –
  • headers (Optional[Dict[str, str]], default: None ) –
  • config (Optional[ProtectConfig], default: None ) –

create_project

create_project(name: str = DEFAULT_PROJECT_NAME, config: Optional[ProtectConfig] = None) -> ProjectResponse

Parameters:

  • name (str, default: DEFAULT_PROJECT_NAME ) –
  • config (Optional[ProtectConfig], default: None ) –

create_stage

create_stage(project_id: Optional[UUID4] = None, name: Optional[str] = None, description: Optional[str] = None, action: Action = PassthroughAction(), action_enabled: bool = False, config: Optional[ProtectConfig] = None) -> StageResponse

Parameters:

  • project_id (Optional[UUID4], default: None ) –
  • name (Optional[str], default: None ) –
  • description (Optional[str], default: None ) –
  • action (Action, default: PassthroughAction() ) –
  • action_enabled (bool, default: False ) –
  • config (Optional[ProtectConfig], default: None ) –

pause_stage

pause_stage(project_id: Optional[UUID4] = None, stage_id: Optional[UUID4] = None, config: Optional[ProtectConfig] = None) -> None

Pause a stage.

If the stage is already paused, the rulesets in the stage will not be evaluated.

Parameters:

  • project_id (Optional[UUID4], default: None ) –
  • stage_id (Optional[UUID4], default: None ) –
  • config (Optional[ProtectConfig], default: None ) –

Parameters:

  • project_id (Optional[UUID4], default: None ) –

    Project ID, by default None and will be taken from the config.

  • stage_id (Optional[UUID4], default: None ) –

    Stage ID, by default None and will be taken from the config.

  • config (Optional[ProtectConfig], default: None ) –

    Protect config, by default None and will be taken from the env vars or the local config file.

Returns:

  • None

Raises:

  • ValueError

    If the project ID is not provided or found.

  • ValueError

    If the stage ID is not provided or found.

resume_stage

resume_stage(project_id: Optional[UUID4] = None, stage_id: Optional[UUID4] = None, config: Optional[ProtectConfig] = None) -> None

Parameters:

  • project_id (Optional[UUID4], default: None ) –
  • stage_id (Optional[UUID4], default: None ) –
  • config (Optional[ProtectConfig], default: None ) –

constants

invoke

TIMEOUT module-attribute

TIMEOUT = total_seconds()

TIMEOUT_MARGIN module-attribute

TIMEOUT_MARGIN = total_seconds()

routes

Routes module-attribute

Routes = SimpleNamespace(invoke='protect/invoke', stages='projects/{project_id}/stages', stage='projects/{project_id}/stages/{stage_id}')

helpers

config

ProtectConfig

Bases: GalileoConfig

Parameters:

  • console_url (Url) –
  • username (str | None, default: None ) –
  • password (SecretStr | None, default: None ) –
  • api_key (SecretStr | None, default: None ) –
  • jwt_token (SecretStr | None, default: None ) –
  • current_user (str | None, default: None ) –
  • config_filename (str, default: 'protect-config.json' ) –
  • project_id (Annotated[UUID, UuidVersion] | None, default: None ) –
  • stage_name (str | None, default: None ) –
  • stage_id (Annotated[UUID, UuidVersion] | None, default: None ) –
config_filename class-attribute instance-attribute
config_filename: str = 'protect-config.json'
project_id class-attribute instance-attribute
project_id: Optional[UUID4] = None
stage_name class-attribute instance-attribute
stage_name: Optional[str] = None
stage_id class-attribute instance-attribute
stage_id: Optional[UUID4] = None
reset
reset() -> None

invoke

invoke

invoke(payload: Payload, prioritized_rulesets: Optional[Sequence[Ruleset]] = None, project_id: Optional[UUID4] = None, stage_name: Optional[str] = None, stage_id: Optional[UUID4] = None, timeout: float = TIMEOUT, metadata: Optional[Dict[str, str]] = None, headers: Optional[Dict[str, str]] = None, config: Optional[ProtectConfig] = None) -> Response

Parameters:

  • payload (Payload) –
  • prioritized_rulesets (Optional[Sequence[Ruleset]], default: None ) –
  • project_id (Optional[UUID4], default: None ) –
  • stage_name (Optional[str], default: None ) –
  • stage_id (Optional[UUID4], default: None ) –
  • timeout (float, default: TIMEOUT ) –
  • metadata (Optional[Dict[str, str]], default: None ) –
  • headers (Optional[Dict[str, str]], default: None ) –
  • config (Optional[ProtectConfig], default: None ) –

ainvoke async

ainvoke(payload: Payload, prioritized_rulesets: Optional[Sequence[Ruleset]] = None, project_id: Optional[UUID4] = None, stage_name: Optional[str] = None, stage_id: Optional[UUID4] = None, timeout: float = TIMEOUT, metadata: Optional[Dict[str, str]] = None, headers: Optional[Dict[str, str]] = None, config: Optional[ProtectConfig] = None) -> Response

Parameters:

  • payload (Payload) –
  • prioritized_rulesets (Optional[Sequence[Ruleset]], default: None ) –
  • project_id (Optional[UUID4], default: None ) –
  • stage_name (Optional[str], default: None ) –
  • stage_id (Optional[UUID4], default: None ) –
  • timeout (float, default: TIMEOUT ) –
  • metadata (Optional[Dict[str, str]], default: None ) –
  • headers (Optional[Dict[str, str]], default: None ) –
  • config (Optional[ProtectConfig], default: None ) –

langchain

PayloadV1

Bases: BaseModel

input class-attribute instance-attribute

input: Optional[str] = None

output class-attribute instance-attribute

output: Optional[str] = None

ProtectTool

Bases: BaseTool

name class-attribute instance-attribute

name: str = 'GalileoProtect'

description class-attribute instance-attribute

description: str = "Protect your LLM applications from harmful content using Galileo Protect. This tool is a wrapper around Galileo's Protect API, can be used to scan text for harmful content, and can be used to trigger actions based on the results.The tool can be used synchronously or asynchronously, on the input text or output text,and can be configured with a set of rulesets to evaluate on."

args_schema class-attribute instance-attribute

args_schema: Type[BaseModel] = PayloadV1

prioritized_rulesets class-attribute instance-attribute

prioritized_rulesets: Optional[Sequence[Ruleset]] = None

project_id class-attribute instance-attribute

project_id: Optional[UUID4] = None

stage_name class-attribute instance-attribute

stage_name: Optional[str] = None

stage_id class-attribute instance-attribute

stage_id: Optional[UUID4] = None

timeout class-attribute instance-attribute

timeout: float = TIMEOUT

config class-attribute instance-attribute

config: Optional[ProtectConfig] = None

_run

_run(input: Optional[str] = None, output: Optional[str] = None) -> str

Apply the tool synchronously.

We serialize the response to JSON because that's what langchain_core expects for tools.

Parameters:

  • input (Optional[str], default: None ) –
  • output (Optional[str], default: None ) –

_arun async

_arun(input: Optional[str] = None, output: Optional[str] = None) -> str

Apply the tool asynchronously.

We serialize the response to JSON because that's what langchain_core expects for tools.

Parameters:

  • input (Optional[str], default: None ) –
  • output (Optional[str], default: None ) –

ProtectParser

Bases: BaseModel

Parameters:

  • chain (Runnable) –

    The chain to trigger if the Protect invocation is not triggered.

  • ignore_trigger (bool, default: False ) –

    Ignore the status of the Protect invocation and always trigger the rest of the chain.

  • echo_output (bool, default: False ) –

    Echo the output of the Protect invocation.

chain class-attribute instance-attribute

chain: Runnable = Field(..., description='The chain to trigger if the Protect invocation is not triggered.')

ignore_trigger class-attribute instance-attribute

ignore_trigger: bool = Field(default=False, description='Ignore the status of the Protect invocation and always trigger the rest of the chain.')

echo_output class-attribute instance-attribute

echo_output: bool = Field(default=False, description='Echo the output of the Protect invocation.')

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

parser

parser(response_raw_json: str) -> str

Parameters:

  • response_raw_json (str) –

project

create_project

create_project(name: str = DEFAULT_PROJECT_NAME, config: Optional[ProtectConfig] = None) -> ProjectResponse

Parameters:

  • name (str, default: DEFAULT_PROJECT_NAME ) –
  • config (Optional[ProtectConfig], default: None ) –

schemas

rule

RuleMetrics

Bases: str, Enum

input_pii class-attribute instance-attribute
input_pii = 'input_pii'
input_sexist class-attribute instance-attribute
input_sexist = 'input_sexist'
input_tone class-attribute instance-attribute
input_tone = 'input_tone'
input_toxicity class-attribute instance-attribute
input_toxicity = 'input_toxicity'
prompt_injection class-attribute instance-attribute
prompt_injection = 'prompt_injection'
pii class-attribute instance-attribute
pii = 'pii'
sexist class-attribute instance-attribute
sexist = 'sexist'
tone class-attribute instance-attribute
tone = 'tone'
toxicity class-attribute instance-attribute
toxicity = 'toxicity'

stage

StageResponse

Bases: Stage

Parameters:

  • name (str) –

    Name of the stage. Must be unique within the project.

  • project_id (UUID) –

    ID of the project to which this stage belongs.

  • description (str | None, default: None ) –

    Optional human-readable description of the goals of this guardrail.

  • action (OverrideAction | PassthroughAction, default: PassthroughAction(type=<ActionType.PASSTHROUGH: 'PASSTHROUGH'>) ) –

    An optional action (kill switch) to take that supersedes all ruleset validations.

  • action_enabled (bool, default: False ) –

    Whether the action is enabled. If False, the action will not be applied.

  • id (UUID) –
id instance-attribute
id: UUID4

stage

create_stage

create_stage(project_id: Optional[UUID4] = None, name: Optional[str] = None, description: Optional[str] = None, action: Action = PassthroughAction(), action_enabled: bool = False, config: Optional[ProtectConfig] = None) -> StageResponse

Parameters:

  • project_id (Optional[UUID4], default: None ) –
  • name (Optional[str], default: None ) –
  • description (Optional[str], default: None ) –
  • action (Action, default: PassthroughAction() ) –
  • action_enabled (bool, default: False ) –
  • config (Optional[ProtectConfig], default: None ) –

pause_stage

pause_stage(project_id: Optional[UUID4] = None, stage_id: Optional[UUID4] = None, config: Optional[ProtectConfig] = None) -> None

Pause a stage.

If the stage is already paused, the rulesets in the stage will not be evaluated.

Parameters:

  • project_id (Optional[UUID4], default: None ) –
  • stage_id (Optional[UUID4], default: None ) –
  • config (Optional[ProtectConfig], default: None ) –

Parameters:

  • project_id (Optional[UUID4], default: None ) –

    Project ID, by default None and will be taken from the config.

  • stage_id (Optional[UUID4], default: None ) –

    Stage ID, by default None and will be taken from the config.

  • config (Optional[ProtectConfig], default: None ) –

    Protect config, by default None and will be taken from the env vars or the local config file.

Returns:

  • None

Raises:

  • ValueError

    If the project ID is not provided or found.

  • ValueError

    If the stage ID is not provided or found.

resume_stage

resume_stage(project_id: Optional[UUID4] = None, stage_id: Optional[UUID4] = None, config: Optional[ProtectConfig] = None) -> None

Parameters:

  • project_id (Optional[UUID4], default: None ) –
  • stage_id (Optional[UUID4], default: None ) –
  • config (Optional[ProtectConfig], default: None ) –