class
GuardrailsApi(superwise_api.entities.base.CoreEntitiyApi):
Used for core entities shared interface: Dashboard, Dataset, Guardrails, Policy, Agent
def
create( self, name: str, description: Optional[str] = None, observability_enabled: bool = True, **kwargs) -> superwise_api.models.guardrails.guardrails.Guardrail:
Create a new guardrail.
Arguments:
- name: The name of the guardrail.
- description: The description of the guardrail.
- observability_enabled: Whether observability is enabled for this 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, observability_enabled: Optional[bool] = None, dataset_id: 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.
- observability_enabled: Whether observability is enabled for this guardrail.
- dataset_id: The dataset ID for storing observability events.
- **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, superwise_api.models.guardrails.guardrails.BlurrinessGuard, superwise_api.models.guardrails.guardrails.ImageResolutionGuard, superwise_api.models.guardrails.guardrails.ImageSemanticsGuard, superwise_api.models.guardrails.guardrails.ImageTamperingGuard, superwise_api.models.guardrails.guardrails.ImageLicensePlateGuard], FieldInfo(annotation=NoneType, required=True, discriminator='type')]], query: str, images: Optional[list[bytes]] = None, **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.
- images: Optional list of images as bytes. If provided, uses multipart/form-data.
- **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, superwise_api.models.guardrails.guardrails.BlurrinessGuard, superwise_api.models.guardrails.guardrails.ImageResolutionGuard, superwise_api.models.guardrails.guardrails.ImageSemanticsGuard, superwise_api.models.guardrails.guardrails.ImageTamperingGuard, superwise_api.models.guardrails.guardrails.ImageLicensePlateGuard], 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, superwise_api.models.guardrails.guardrails.BlurrinessGuard, superwise_api.models.guardrails.guardrails.ImageResolutionGuard, superwise_api.models.guardrails.guardrails.ImageSemanticsGuard, superwise_api.models.guardrails.guardrails.ImageTamperingGuard, superwise_api.models.guardrails.guardrails.ImageLicensePlateGuard], 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, model_provider_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.
- model_provider_with_deleted: Whether to include versions of deleted model providers.
- **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, images: Optional[list[bytes]] = None, **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.
- images: Optional list of images as bytes. If provided, uses multipart/form-data.
- **kwargs: Arbitrary keyword arguments.
Returns:
The validation of each guardrule.
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.
def
verify_dataset_schema(self, dataset_id: str, **kwargs) -> bool:
Verify that a dataset has the required schema for guardrail observability.
Arguments:
- dataset_id: The ID of the dataset to verify.
- **kwargs: Arbitrary keyword arguments.
Returns:
bool: True if the dataset schema matches the required guardrail schema, False otherwise.
def
create_dataset( self, guardrail_id: str, name: Optional[str] = None, **kwargs) -> superwise_api.models.dataset.dataset.Dataset:
Inherited Members
- superwise_api.entities.base.BaseApi
- BaseApi
- api_client
- wrap_api_calls
- raise_exception
- superwise_api.entities.base.CoreEntitiyApi
- archive
- unarchive
- bulk_action