superwise_api.entities.guardrails

class GuardrailsApi(superwise_api.entities.base.BaseApi):
def create( self, name: str, description: Optional[str] = None, **kwargs) -> superwise_api.models.guardrails.guardrails.Guardrail:

Create a new guardrail.

Arguments:
  • name: The name of the guardrail.
  • description: The description of the guardrail.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The created guardrail.

def get_by_id( self, guardrail_id: str, with_deleted: bool = False, **kwargs) -> superwise_api.models.guardrails.guardrails.Guardrail:

Get a guardrail by id.

Arguments:
  • guardrail_id: The id of the guardrail.
  • with_deleted: Whether to include deleted guardrails.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The guardrail.

def get( self, search: Optional[str] = None, ids: Optional[set[uuid.UUID]] = None, page: Optional[Annotated[int, Strict(strict=True), Interval(gt=None, ge=1, lt=None, le=None), None]] = None, size: Optional[Annotated[int, Strict(strict=True), Interval(gt=None, ge=25, lt=None, le=500), None]] = None, with_deleted: bool = False, **kwargs) -> superwise_api.client.models.page.Page:

Gets guardrails. Filter if any of the parameters are provided.

Arguments:
  • search (str, optional): The search query.
  • page (int, optional): The page number.
  • size (int, optional): The size of the page.
  • with_deleted: Whether to include deleted guardrails.
Returns:

Page: A page of guardrails.

def update( self, guardrail_id: str, name: Optional[str] = None, description: Optional[str] = None, **kwargs) -> superwise_api.models.guardrails.guardrails.Guardrail:

Update a guardrail.

Arguments:
  • guardrail_id: The id of the guardrail.
  • name: The name of the guardrail.
  • description: The description of the guardrail.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The updated guardrail.

def delete(self, guardrail_id: str, **kwargs) -> None:

Delete a guardrail.

Arguments:
  • guardrail_id: The id of the guardrail.
  • **kwargs: Arbitrary keyword arguments.
Returns:

None

def run_guardrules( self, tag: Literal['input', 'output'], guardrules: list[typing.Annotated[typing.Union[superwise_api.models.guardrails.guardrails.ToxicityGuard, superwise_api.models.guardrails.guardrails.AllowedTopicsGuard, superwise_api.models.guardrails.guardrails.RestrictedTopicsGuard, superwise_api.models.guardrails.guardrails.CorrectLanguageGuard, superwise_api.models.guardrails.guardrails.StringCheckGuard, superwise_api.models.guardrails.guardrails.CompetitorCheckGuard, superwise_api.models.guardrails.guardrails.PiiDetectionGuard, superwise_api.models.guardrails.guardrails.DetectJailbreakGuard], FieldInfo(annotation=NoneType, required=True, discriminator='type')]], query: str, **kwargs) -> list[superwise_api.models.guardrails.guardrails.GuardrailValidationResponse]:

Validate guards on a given input query.

Arguments:
  • tag: The query type.
  • guardrules: The guardrules to validate.
  • query: The query to validate.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The validation of each guardrule.

def validate_guardrules( self, guardrules: list[typing.Annotated[typing.Union[superwise_api.models.guardrails.guardrails.ToxicityGuard, superwise_api.models.guardrails.guardrails.AllowedTopicsGuard, superwise_api.models.guardrails.guardrails.RestrictedTopicsGuard, superwise_api.models.guardrails.guardrails.CorrectLanguageGuard, superwise_api.models.guardrails.guardrails.StringCheckGuard, superwise_api.models.guardrails.guardrails.CompetitorCheckGuard, superwise_api.models.guardrails.guardrails.PiiDetectionGuard, superwise_api.models.guardrails.guardrails.DetectJailbreakGuard], FieldInfo(annotation=NoneType, required=True, discriminator='type')]], **kwargs) -> list[superwise_api.models.guardrails.guardrails.GuardrailValidationResponse]:

Validate guards on a given input query.

Arguments:
  • guardrules: The guardrules to validate.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The validation of each guardrule.

def gardrules_types(self, **kwargs) -> list[str]:

Get the types of the available guardrules.

Returns:

A list of available guardrule types.

def gardrules_schema(self, **kwargs) -> list[dict]:

Get the schema of the available guardrules.

Returns:

A list of available guardrule schemas.

def create_version( self, guardrail_id: str, name: str, guardrules: list[typing.Annotated[typing.Union[superwise_api.models.guardrails.guardrails.ToxicityGuard, superwise_api.models.guardrails.guardrails.AllowedTopicsGuard, superwise_api.models.guardrails.guardrails.RestrictedTopicsGuard, superwise_api.models.guardrails.guardrails.CorrectLanguageGuard, superwise_api.models.guardrails.guardrails.StringCheckGuard, superwise_api.models.guardrails.guardrails.CompetitorCheckGuard, superwise_api.models.guardrails.guardrails.PiiDetectionGuard, superwise_api.models.guardrails.guardrails.DetectJailbreakGuard], FieldInfo(annotation=NoneType, required=True, discriminator='type')]], description: str | None = None, **kwargs) -> superwise_api.models.guardrails.guardrails.GuardrailVersion:

Create a new guardrail version.

Arguments:
  • guardrail_id: The id of the guardrail.
  • name: The name of the guardrail version.
  • description: The description of the guardrail version.
  • guardrules: The rules of the guardrail version.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The created guardrail version.

def get_versions( self, guardrail_id: str, ids: Optional[set[uuid.UUID]] = None, name: Optional[str] = None, created_by: Optional[str] = None, with_deleted: bool = False, **kwargs) -> list[superwise_api.models.guardrails.guardrails.GuardrailVersion]:

Gets guardrail versions. Filter if any of the parameters are provided.

Arguments:
  • guardrail_id: The id of the guardrail.
  • ids: The ids of the guardrail versions.
  • name: The name of the guardrail version.
  • created_by: The creator of the guardrail version.
  • with_deleted: Whether to include versions of deleted guardrails.
  • **kwargs: Arbitrary keyword arguments.
Returns:

List[GuardrailVersion]: A list of guardrail versions.

def update_version( self, id: str, name: Optional[str] = None, description: Optional[str] = None, **kwargs) -> superwise_api.models.guardrails.guardrails.GuardrailVersion:

Update a guardrail version.

Arguments:
  • id: The id of the guardrail version.
  • name: The name of the guardrail version.
  • description: The description of the guardrail version.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The updated guardrail version.

def run_versions( self, tag: Literal['input', 'output'], ids: set[uuid.UUID], query: str, **kwargs) -> list[superwise_api.models.guardrails.guardrails.GuardrailValidationResponse]:

Validate guardrules on a given input query.

Arguments:
  • tag: The tag of the guardrail.
  • ids: The ids of the guardrail versions to validate.
  • query: The input query to validate.
  • **kwargs: Arbitrary keyword arguments.
Returns:

The validation of each guardrule.

def add_tags(self, guardrail_id: str, tag_ids: list[str], **kwargs):

Add tags to an guardrail.

Arguments:
  • guardrail_id (str): The id of the guardrail.
  • tag_ids list(str): List of tag ids to add the guardrail
Returns:

None

def remove_tags(self, guardrail_id: str, tag_ids: list[str], **kwargs):

Delete tags from an guardrail.

Arguments:
  • guardrail_id (str): The id of the guardrail.
  • tag_ids list(str): List of tag ids to remove from the guardrail
Returns:

None

def search( self, filters: list[typing.Any] | None = None, search: str | None = None, sort_by: str | None = None, sort_direction: Literal['asc', 'desc'] = 'desc', **kwargs) -> superwise_api.client.models.page.Page:

Searches for guardrails based on a prefix.

Arguments:
  • filters (list[Any]): Filter on db columns, list of tuples. e.g. [[["id", "eq", "5c05dc9f-f04a-4ce8-9d57-2ec63ee76aac"], "and", ["description", "ilike", "Construction"]], "or", ["name", "ilike", "active"]]
  • search (str): Free text search on searchable fields
  • sort_by (str): Field to sort by
  • sort_direction (Literal["asc", "desc"]): Sort direction (ascending or descending)
  • query_params can be passed as part of the kwargs for pagination
Returns:

Page: A page of guardrails.

Inherited Members
superwise_api.entities.base.BaseApi
BaseApi
api_client
wrap_api_calls
raise_exception