> ## Documentation Index
> Fetch the complete documentation index at: https://futureagi.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Protect

> Use FutureAGI Protect to protect your data

You can checkout the [colab notebook](https://colab.research.google.com/drive/1ver05a3vBrYVfeM8NWqDU-TsaMsLT3cQ?usp=sharing) to quickly get started with the FutureAGI Protect. <a href="https://colab.research.google.com/drive/1ver05a3vBrYVfeM8NWqDU-TsaMsLT3cQ?usp=sharing"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" /></a>

## Installing FutureAGI SDK

```bash theme={null}
pip install futureagi
pip install ai-evaluation
```

## Initializing FutureAGI Protect

```python theme={null}
from fi.evals import Protect

protector = Protect(fi_api_key="<your_api_key>", 
                  fi_secret_key="<your_api_secret>") # Optional, if you want to set the API key and secret key manually
```

<Tip>
  Click [here](/admin-settings#accessing-api-keys) to learn how to access your API keys.
  It's recommended to set the API key and secret key as environment variables.
</Tip>

## Define Protect Rules and the Action to take

```python theme={null}
# Example Ruleset
rules = [
    {
        "metric": "Tone",
        "contains": ["anger", "fear"],
        "type": "any"
    },
    {
        "metric": "Toxicity"
    }
]

action = "This message cannot be displayed"
```

## Apply Protect on a text

```python theme={null}
# Apply the rules to a text
response = protector.protect("Hello, world!", 
                            protect_rules=rules, 
                            action=action,
                            reason=True,
                            timeout=25)
print(response)
```

## Example Script using Anthropic Client and FutureAGI Protect

```python theme={null}
# Define the environment variables

# export ANTHROPIC_API_KEY=<your_api_key>
# export FI_API_KEY=<your_api_key>
# export FI_SECRET_KEY=<your_api_secret>



from anthropic import Anthropic
from fi.evals import Protect

anthropic = Anthropic()

protector = Protect()

response = anthropic.messages.create(
    max_tokens=1000,
    model="claude-3-5-sonnet-20240620",
    messages=[
        {"role": "user", "content": "Hi, I am a student, Can you help me with my homework?"}
    ]
)

rules = [
    {
        "metric": "Tone",
        "contains": ["anger", "fear"],
        "type": "any"
    },
    {
        "metric": "Toxicity"
    }
]

action = "This message cannot be displayed"
response_to_protect = response.content[0].text
protect_response = protector.protect(response_to_protect, 
                            protect_rules=rules, 
                            action=action,
                            reason=True,
                            timeout=25)

print(protect_response)
print(response_to_protect)
```

<Tip>
  Optionally you can just use the `protect` function from the FutureAGI SDK, without initializing the `Protect` class.
</Tip>

```python theme={null}
from fi.evals import protect

rules = [
    {
        "metric": "Tone",
        "contains": ["anger", "fear"],
        "type": "any"
    },
]

action = "This message cannot be displayed"
protected_response = protect("Hello, world!", 
                            protect_rules=rules, 
                            action=action,
                            reason=True,
                            timeout=25)
print(protected_response)
```
