- A metric
- An operator
- A target value
true
, then the rule has been broken and is triggered. You can then use this in your code to change the response from your application.
Create rules
To create a rule, create an instance of theRule
, setting the metric and operator. Set the target values as needed (for example, for the empty
and not_empty
operators, there is no need to set a target value).
The metric uses the GalileoScorers
enum, and the operator uses the RuleOperator
enum.
Value | Type | Description | Notes |
---|---|---|---|
RuleOperator.gt | Numerical | Greater than | |
RuleOperator.lt | Numerical | Less than | |
RuleOperator.gte | Numerical | Greater than or equal | |
RuleOperator.lte | Numerical | Less than or equal | |
RuleOperator.eq | Numerical or Categorical | Equals | |
RuleOperator.neq | Numerical or Categorical | Not equals | |
RuleOperator.contains | Categorical | Contains | Does the list of categories contain the single target values |
RuleOperator.all | Categorical | All | Does the list of categories contain all the target values |
RuleOperator.any | Categorical | Any | Does the list of categories contain any of the target values |
RuleOperator.empty | Categorical | Empty | Is the list of categories empty |
RuleOperator.not_empty | Categorical | Not empty | Is the list of categories not empty |
Metrics and Operators supported
Rules support the following Luna-2 metrics:- Action Advancement
- Action Completion
- Completeness
- Context Adherence
- PII
- Prompt Injection
- Sexism
- Tone
- Tool Errors
- Tool Selection Quality
- Toxicity
Action advancement
This rule measures if your agent accomplishes, or is making progress towards a goal. Read more about action advancement.Setting | Value |
---|---|
Metric | GalileoScorers.action_advancement |
Required Payload Fields | Both input and output must be included |
Values | 0.0 - 1.0 |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
Action completion
This rule measures if your agent successfully accomplished all of the user’s goals. Read more about action completion.Setting | Value |
---|---|
Metric | GalileoScorers.action_completion |
Required Payload Fields | Both input and output must be included |
Values | 0.0 - 1.0 |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
Completeness
This rule measures how thoroughly your model’s response covered the relevant information available in the context provided. Read more about completeness.Setting | Value |
---|---|
Metric | GalileoScorers.completeness |
Required Payload Fields | Both input and output must be included |
Values | 0.0 - 1.0 |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
Context Adherence
This rule measures whether your model’s response was purely based on the context provided. It can be used to stop hallucinations from reaching your end users. Read more about context adherence.Setting | Value |
---|---|
Metric | GalileoScorers.context_adherence |
Required Payload Fields | Both input and output must be included |
Values | 0.0 - 1.0 |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
0.1
is a good threshold below which the response is not adhering to the context. Creating a rule for less than 0.1 will trigger the rule when the response does not adhere to the provided context.
PII (Personal Identifiable Information)
This rule is used to detect and stop Personal Identifiable Information (PII). When applied on the input, it can be used to stop the user or company PII from being included in API calls to external services. When applied on the output, it can be used to prevent data leakage or PII being shown back to the user. Read more about PII categories and their definitions.Setting | Value |
---|---|
Metric | GalileoScorers.input_pii (for detecting PII in the input)GalileoScorers.output_pii (for detecting PII in the output) |
Required Payload Fields | input for input PII, output for output PII |
Values | Depending on the operator, one or more of:account_info address credit_card_info date_of_birth email name network_info password phone_number ssn username |
Operators supported | Any (RuleOperator.any ) - A list of categoriesAll ( RuleOperator.all ) - A list of categoriesContains ( RuleOperator.contains ) - A single categoryEqual ( RuleOperator.eq ) - A single categoryNot equal ( RuleOperator.neq ) - A single categoryEmpty ( RuleOperator.empty )Not empty ( RuleOperator.not_empty ) |
Prompt Injection
This rule is used to detect and stop prompt injections in the input. Read more about Prompt Injection.Setting | Value |
---|---|
Metric | GalileoScorers.prompt_injection |
Required Payload Fields | input |
Values | Depending on the operator, one or more of:impersonation obfuscation simple_instruction few_shot new_context |
Operators supported | Any (RuleOperator.any ) - A list of categoriesAll ( RuleOperator.all ) - A list of categoriesContains ( RuleOperator.contains ) - A single categoryEqual ( RuleOperator.eq ) - A single categoryNot equal ( RuleOperator.neq ) - A single categoryEmpty ( RuleOperator.empty )Not empty ( RuleOperator.not_empty ) |
Sexism
This rule is used to. detect sexist or biased language. When applied on the input, it can be used to detect sexist remarks in user queries. When applied on the output, it can be used to prevent your application from using an making biased or sexist comments in its responses. Read more about sexism.Setting | Value |
---|---|
Metric | GalileoScorers.input_sexism (for detecting sexism in the input)GalileoScorers.output_sexism (for detecting sexism in the output) |
Required Payload Fields | input for input sexism, output for output sexism |
Values | 0.0 - 1.0. Higher values indicate higher sexism. |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
Tone
This rule is used to detect the primary tone from the text. When applied on the input, it can be used to detect negative tones in user queries. When applied on the output, it can be used to prevent your application from using an undesired tone in its responses. Read more about tone.Setting | Value |
---|---|
Metric | GalileoScorers.input_tone (for detecting tone in the input)GalileoScorers.output_tone (for detecting tone in the output) |
Required Payload Fields | input for input tone, output for output tone |
Values | One of:anger annoyance confusion fear joy love sadness surprise neutral |
Operators supported | Equal (RuleOperator.eq ) - A single categoryNot equal ( RuleOperator.neq ) - A single category |
Tool errors
This rule measures any errors when executing tools. Read more about tool errors.Setting | Value |
---|---|
Metric | GalileoScorers.tool_error_rate |
Required Payload Fields | Both input and output must be included |
Values | 0.0 - 1.0 |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
Tool selection quality
This rule measures whether the agent selected the correct tool, and for each tool passed the correct arguments. Read more about tool selection quality.Setting | Value |
---|---|
Metric | GalileoScorers.tool_selection_quality |
Required Payload Fields | Both input and output must be included |
Values | 0.0 - 1.0 |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
Toxicity
This rule is used to detect and stop toxic or foul language in the input (user query) or output (response shown to the user). Read more about toxicity.Setting | Value |
---|---|
Metric | GalileoScorers.input_toxicity (for detecting toxicity in the input)GalileoScorers.output_toxicity (for detecting toxicity in the output) |
Required Payload Fields | input for input toxicity, output for output toxicity |
Values | 0.0 - 1.0. Higher values indicate higher toxicity. |
Operators supported | Greater than (RuleOperator.gt )Less than ( RuleOperator.lt )Greater than or equal ( RuleOperator.gte )Less than or equal ( RuleOperator.lte ) |
Custom code-based metrics
You can use custom code-based metrics in your runtime protection rulesets.Related resources
Runtime protection basics
Learn the basics of running runtime protection.
Rulesets
Learn about defining rulesets for runtime protection.
Stages
Learn about defining stages for runtime protection to be used during different stages in your application workflow.
Invoke runtime protection
Learn how to invoke runtime protection in code using the Galileo SDK.