Murnitur Shield is designed to protect your system from bad inputs and safeguard your users from harmful outputs. Think of it as a firewall for your data, ensuring that only appropriate content gets through.

Generate API Key

  • Visit murnitur.ai and sign in to your account.
  • Navigate to the API key section and generate a new API key.

Install Murnitur

Install the Murnitur package using pip:

Define Rulesets

Rulesets are the core of Murnitur Shield, containing specific rules your application must comply with. They help determine what gets flagged or filtered based on predefined criteria.

Example ruleset:

Each ruleset includes:

  • Metric: The type of content to check (e.g., PII).
  • Operator: The condition to evaluate (e.g., “contains”).
  • Value: Specific values to look for (e.g., “email”, “ssn”).
  • Action: What to do if a rule is triggered, such as overriding the response with a fallback message.

Start the Firewall

Initialize Murnitur Shield to start filtering content:

Quick Wiki

payload

The payload parameter is a dictionary containing the data you want to inspect and filter. It typically includes:

  • input: The original input data from the user.
  • output: The generated output data from your system.

Example:

python
payload = {
    "input": "User input data here",
    "output": "Generated output data here"
}

rulesets

The rulesets parameter is a list of RuleSet objects defining the rules your application must comply with. Each RuleSet contains:

  • rules: A list of individual rules to check against the payload.
    • metric: The type of content to evaluate (e.g., “pii” for Personally Identifiable Information).
    • operator: The condition to apply (e.g., “contains”).
    • value: Specific values to look for (e.g., [“email”, “ssn”]).
  • action: The action to take if a rule is triggered.
    • type: The type of action (e.g., “OVERRIDE”).
    • fallback: The fallback response if the action type is “OVERRIDE”.

Example:

python
rulesets = [
    {
        "rules": [
            {
                "metric": "pii",
                "operator": "contains",
                "value": ["email", "ssn", "address", "phone_number"]
            }
        ],
        "action": {
            "type": "OVERRIDE",
            "fallback": "Sorry, I can't provide personal identifiable information."
        }
    }
]

config

The config parameter is a dictionary containing various configuration options for Murnitur Shield. It includes keys such as murnitur_key, provider, model, group, api_key, base_url, and headers.

Example:

python
from murnitur.main import GuardConfig

config: GuardConfig

murnitur_key

The murnitur_key is a required string containing your Murnitur API key. This key authenticates your requests, captures interceptions, and links them to your account. If not passed, murnitur picks it up from the environment variables.

python
config["murnitur_key"] = "your_murnitur_api_key_here"

provider

The provider parameter specifies the service provider you are using, such as “openai”, “groq”, “anthropic”, or “custom”.

Example:

config["provider"] = "openai"

model

By default, Murnitur uses gpt-3.5-turbo, but you can change it to any supported model from your chosen provider.

Example:

config["model"] = "gpt-4-turbo"

group

The group parameter is an optional string that categorizes the set of rules being applied. It helps in organizing and managing different rule sets for various environments or projects.

Example:

config["group"] = "development"

api_key

The api_key is an optional string containing your API key for the chosen provider. This key is required if you use any provider-specific metrics in your rule sets.

Example:

config["api_key"] = "your_provider_api_key_here"

base_url

The base_url is an optional string specifying the base URL for API requests. This is useful if you need to point to a different endpoint. It must be an OpenAI compatible API endpoint.

Example:

config["base_url"] = "https://api.openai.com/v1"

headers

The headers parameter is an optional dictionary containing any additional headers you need to include in your API requests.

Example:

config["headers"] = {"Custom-Header": "value"}

Complete Example

Here is a complete example of using Murnitur Shield with all the parameters: