Guardrail Manager
GuardrailManager
Bases: Model
GuardrailManager is responsible for managing and executing a series of guardrails
on a given prompt. It utilizes the weave
framework to define operations that
can be applied to the guardrails.
Attributes:
Name | Type | Description |
---|---|---|
guardrails |
list[Guardrail]
|
A list of Guardrail objects that define the rules and checks to be applied to the input prompt. |
Source code in guardrails_genie/guardrails/manager.py
guard(prompt, progress_bar=True, **kwargs)
Execute a series of guardrails on a given prompt and return the results.
This method iterates over a list of Guardrail objects, applying each guardrail's
guard
method to the provided prompt. It collects responses from each guardrail
and compiles them into a summary report. The function also determines the overall
safety of the prompt based on the responses from the guardrails.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The input prompt to be evaluated by the guardrails. |
required |
progress_bar
|
bool
|
If True, displays a progress bar while processing the guardrails. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to be passed to each guardrail's
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing: - "safe" (bool): Indicates whether the prompt is considered safe based on the guardrails' evaluations. - "alerts" (list): A list of dictionaries, each containing the name of the guardrail and its response. - "summary" (str): A formatted string summarizing the results of each guardrail's evaluation. |
Source code in guardrails_genie/guardrails/manager.py
predict(prompt, **kwargs)
Predicts the safety and potential issues of a given input prompt using the guardrails.
This function serves as a wrapper around the guard
method, providing a simplified
interface for evaluating the input prompt without displaying a progress bar. It
applies a series of guardrails to the prompt and returns a detailed assessment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The input prompt to be evaluated by the guardrails. |
required |
**kwargs
|
Additional keyword arguments to be passed to each guardrail's
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing: - "safe" (bool): Indicates whether the prompt is considered safe based on the guardrails' evaluations. - "alerts" (list): A list of dictionaries, each containing the name of the guardrail and its response. - "summary" (str): A formatted string summarizing the results of each guardrail's evaluation. |