RIME AI Firewall

Activation for firewall.

class rime.tabular.firewall.activate.TabularFirewall(rules: List[BatchTabularFirewallRule], silent_errors: bool = False, model: Optional[TabularBlackBoxModel] = None, model_task: Optional[ModelTask] = None, upload_client: Optional[FirewallUploader] = None)

Base firewall class, initialized with a set of firewall rules.

classmethod from_components(firewall_id: str, firewall_client: FirewallClient, json_file_path: Optional[str] = None, **kwargs: Any) TabularFirewall

Create firewall from necessary information.

Parameters:
  • firewall_id (str) – The Firewall ID, obtained from AI Firewall configuration in the UI.

  • json_file_path (str) – The path to the JSON configuration file.

  • firewall_client (rime.core.client.FirewallClient) – A client used to fetch necessary information used to instantiate the firewall.

  • upload_client (rime.tabular.firewall.uploader.FirewallUploader) – A client used to upload results to the backend server.

  • silent_errors (bool) – If True, then don’t raise an error on unexpected inputs. If False, then allow exceptions to be raised.

  • predict_dict (Optional[Callable]) – Model prediction function.

  • model_task (rime.tabular.base.schema.ModelTask) – Enum representing model task.

property model_task: ModelTask

Getter for model_task.

add_rule(new_rule: BatchTabularFirewallRule) None

Add a new validation rule to this firewall.

Parameters:

new_rule (BatchTabularFirewallRule) – Firewall rule to append to the firewall.

validate_batch(batch: DataFrame, data_ids: Optional[Series] = None, preds: Optional[ndarray] = None, timestamps: Optional[Series] = None, parallelize_computation: bool = False, num_processes: int = 9) List[FirewallResponse]

Validate a batch of data against all firewall rules.

Parameters:
  • batch (pd.DataFrame) – A batch of datapoints that firewall will process.

  • data_ids – (Optional[pd.Series]): Optional list of data id’s.

Returns:

A list of FirewallResponse objects, one per datapoint.

Return type:

List[FirewallResponse]

validate_batch_and_upload(batch: DataFrame, data_ids: Optional[Series] = None, preds: Optional[ndarray] = None, timestamps: Optional[Series] = None, wait_for_completion: bool = False, minibatch_size: int = 5000) None

Validate a batch of data against all firewall rules and Upload.

Parameters:
  • batch (pd.DataFrame) – A batch of datapoints that firewall will process.

  • data_ids – (Optional[pd.Series]): Optional list of data id’s.

Returns:

A list of FirewallResponse objects, one per datapoint.

Return type:

List[FirewallResponse]

get_summary(batch_rule_responses: List[FirewallBatchRuleResponse]) FirewallResponseSummary

Get firewall summary for a given datapoint.

This provides an aggregate action as well as total # warnings, given the rule responses after validating on a given datapoint.

Parameters:

rule_responses (List[FirewallBatchRuleResponse]) – Set of rule responses obtained after validate_single on a given datapoint.

Returns:

List of FirewallBatchRuleResponse objects, each corresponding to the firewall response of a given rule to the provided datapoint.

Return type:

List[FirewallBatchRuleResponse]

validate_single(datapoint: dict, data_id: Optional[str] = None, pred: Optional[Any] = None, timestamp: Optional[datetime] = None) FirewallResponse

Validate a single datapoint against all firewall rules.

Parameters:
  • datapoint (dict) – A given datapoint, in dictionary form.

  • data_id (Optional[str]) – Optional data id.

Returns:

A FirewallResponse object, containing summary info as well as a list of FirewallBatchRuleResponse objects.

Return type:

FirewallResponse

validate_single_and_upload(datapoint: dict, data_id: Optional[str] = None, pred: Optional[Any] = None, wait_for_completion: bool = False) FirewallResponse

Validate a single datapoint against firewall rules and upload to server.

Errors if upload_endpoint/firewall_id were not specified during firewall instantiation.

Parameters:
  • datapoint (dict) – A given datapoint, in dictionary form.

  • data_id (Optional[str]) – Optional data id.

Returns:

A FirewallResponse object, containing summary info as well as a list of FirewallBatchRuleResponse objects.

Return type:

FirewallResponse

set_flagged_action_for_rule(test_type: DataTestType, flagged_action: FirewallAction, col_names: Optional[List] = None) None

Set flagged action for firewall rule.

This provides the ability to override the default action to take for a given firewall rule when a datapoint fails the rule. You may set the action to FirewallAction.FLAG, FirewallAction.IMPUTE, or FirewallAction.BLOCK, to flag, impute, or block the datapoint respectively.

Parameters:
  • test_type (DataTestType) – DataTestType of the corresponding data test.

  • flagged_action (FirewallAction) – One of FirewallAction.FLAG, FirewallAction.IMPUTE, or FirewallAction.BLOCK

  • col_names (Optional[List]) – If specified, the set of columns to configure the flagged_action over.

set_global_flagged_action(flagged_action: FirewallAction) None

Set global flagged action for all firewall rules.

class rime.tabular.firewall.activate.FirewallUploader(firewall_id: str, firewall_uploader_client: FirewallUploaderClient)

Uploader for firewall responses.

classmethod from_url(firewall_id: str, upload_endpoint: str, **kwargs: Any) FirewallUploader

Construct uploader from url directly.

get_rule_response_dicts(rule_responses: List[FirewallBatchRuleResponse]) List[Dict]

Get and construct firewall rule response dict.

upload(response: FirewallResponse, max_retries: int = 10, wait_for_completion: bool = False) None

Upload response to the backend server.

upload_batch(responses: List[FirewallResponse], max_retries: int = 10, wait_for_completion: bool = False) None

Upload response to the backend server.