For the complete documentation index, see llms.txt. This page is also available as Markdown.

Alinia Guardrail Usage

Alinia Guardrail Usage

Open In Colab

import os
from getpass import getpass


def ensure_env_var(name: str) -> None:
    """Prompt for an environment variable if not already set."""
    if name not in os.environ:
        print(f"{name} not found in environment!")
        value = getpass(f"Please enter your {name}: ")
        os.environ[name] = value
        print(f"{name} set for this session!")
    else:
        print(f"{name} found in environment.")


for var in ["ALINIA_API_KEY", "ALINIA_ENDPOINT"]:
    ensure_env_var(var)

Basic Usage

Output should look like:

Advanced Usage

Let's customize the behavior of Alinia's guardrails. For more information, please see our docs.

Customizing the detection_config

You can adjust the detection_config by declaring the model version and classification threshold.

To change the recommended response, which we will show how to access below, you can set the blocked_response parameter either in the AnyGuardrail constructor:

Or you can set it after the guardrail is constructed:

Output: {'action': 'block', 'output': "I'm sorry, Dave. I'm afraid I can't do that."}

Last updated