Skip to content

watsonx.governance

WatsonxGuardrail #

Bases: BaseGuardrail

Provides functionality to interact with IBM watsonx.governance Guardrails.

Info

Beekeeper currently does not support agent_function_call_validation policy provided by IBM Watsonx Governance Guardrails manager.

Attributes:

Name Type Description
api_key str

The API key for IBM watsonx.governance.

policy_id str

The policy ID in watsonx.governance.

inventory_id str

The inventory ID in watsonx.governance.

instance_id str

The instance ID in watsonx.governance.

region Region

The region where watsonx.governance is hosted when using IBM Cloud. Defaults to us-south.

Example
from beekeeper.guardrails.watsonx.supporting_classes.enums import Region

from beekeeper.guardrails.watsonx import (
    WatsonxGuardrail,
)

# watsonx.governance (IBM Cloud)
guardrails_manager = WatsonxGuardrail(
    api_key="API_KEY",
    policy_id="POLICY_ID",
    inventory_id="INVENTORY_ID",
    instance_id="INSTANCE_ID",
    region=Region.US_SOUTH,
)

model_post_init #

model_post_init(__context)

Initialize region and token manager after Pydantic validation.

enforce #

enforce(text: str, direction: Direction | str, prompt_template: PromptTemplate | str | None = None, context: list = []) -> GuardrailResponse

Runs policies enforcement to specified guardrail.

Parameters:

Name Type Description Default
text str

The input text that needs to be evaluated or processed according to the guardrail policy.

required
direction Direction

Whether the guardrail is processing the input or generated output.

required
prompt_template PromptTemplate

The prompt template.

None
context list

List of context.

[]
Example
from beekeeper.guardrails.watsonx.supporting_classes.enums import Direction

guardrails_manager.enforce(
    text="Hi, How can I help you?",
    direction=Direction.OUTPUT,
)

Enums#

Region #

Bases: str, Enum

Supported IBM watsonx.governance regions.

Defines the available regions where watsonx.governance SaaS services are deployed.

Attributes:

Name Type Description
US_SOUTH str

"us-south".

EU_DE str

"eu-de".

AU_SYD str

"au-syd".

Direction #

Bases: str, Enum

Supported IBM watsonx.governance directions (input/output).

Attributes:

Name Type Description
INPUT str

"input".

OUTPUT str

"output".