Run Protect via SDK

Set up and configure Protect to apply real-time safety checks to your AI application's inputs and outputs.

What it is

Run Protect via SDK is the programmatic interface to Future AGI’s real-time guardrailing system. It exposes rule-based safety checks across four dimensions — Content Moderation, Bias Detection, Security, and Data Privacy Compliance — for text, image, and audio inputs, with configurable actions, explanations, and fail-fast evaluation behavior.


Use cases

  • Block toxic or harmful content — Screen user inputs or model outputs for hate speech, threats, and harassment before they reach end users.
  • Detect prompt injection — Catch adversarial attempts to override instructions or manipulate your AI system.
  • Enforce data privacy — Automatically flag PII (names, emails, phone numbers, SSNs) to stay GDPR/HIPAA compliant.
  • Multi-modal safety — Apply the same rules to text, image URLs, and audio files without separate pipelines.
  • Apply multiple rules at once — Bundle all four safety dimensions in one call for comprehensive protection.

How to

Setting API Key

Set up your Future AGI account and get started with Future AGI’s robust SDKs. Follow the QuickStart guide:

Tip

Click here to learn how to access your API key.

Installation and Setup

To begin using Protect initialize the Protect instance. This will handle the communication with the API and apply defined safety checks.

from fi.evals import Protect

# Initialize Protect client (uses environment variables FI_API_KEY and FI_SECRET_KEY)
protector = Protect()

# Or initialize with explicit credentials
protector = Protect(
    fi_api_key="your_api_key_here",
    fi_secret_key="your_secret_key_here"
)

Protect automatically reads FI_API_KEY and FI_SECRET_KEY from your environment variables if not explicitly provided.

Define Protect Rules

The protect() method accepts several arguments and rules to configure your protection checks.

Arguments:

ArgumentTypeDefault ValueDescription
inputsstring or list[string]Input to be evaluated. Can be text, image URL/path, audio URL/path, or data URI
protect_rulesList[Dict]List of safety rules to apply
actionstring"Response cannot be generated as the input fails the checks"Custom message shown when a rule fails
reasonboolFalseInclude detailed explanation of why content failed
timeoutint30000Max time in milliseconds for evaluation

Rules are defined as a list of dictionaries. Each rule specifies which safety dimension to check.

KeyRequiredTypeValuesDescription
metricyesstringcontent_moderation, bias_detection, security, data_privacy_complianceWhich safety dimension to check
actionnostringAny custom messageOverride the default action message for this specific rule
rules = [
    {"metric": "content_moderation"},
    {"metric": "bias_detection"},
    {"metric": "security"},
    {"metric": "data_privacy_compliance"}
]
  • Evaluation stops as soon as one rule fails (fail-fast behavior)
  • Rules are processed in parallel batches for optimal performance
  • All four safety dimensions work across text, image, and audio modalities

Run and read the result

Call protector.protect() with your input and rules. When a check is run, a response dictionary is returned with detailed results.

KeyTypeDescription
statusstring"passed" or "failed" - result of rule evaluation
messagesstringCustom action message (if failed) or original input (if passed)
completed_ruleslist[string]Rules that were successfully evaluated
uncompleted_ruleslist[string]Rules skipped due to early failure or timeout
failed_rulelist[string]Which rule(s) caused the failure (empty if passed)
reasonslist[string]Explanation(s) of failure or ["All checks passed"]
time_takenfloatTime taken in seconds
result = protector.protect(
    "AI Generated Message",
    protect_rules=rules,
    action="I'm sorry, I can't help you with that.",
    reason=True,
    timeout=25000
)
print(result)

Pass:

{
    'status': 'passed',
    'completed_rules': ['content_moderation', 'bias_detection'],
    'uncompleted_rules': [],
    'failed_rule': [],
    'messages': 'I like apples',
    'reasons': ['All checks passed'],
    'time_taken': 0.234
}

Fail:

{
    'status': 'failed',
    'completed_rules': ['content_moderation', 'bias_detection'],
    'uncompleted_rules': ['security', 'data_privacy_compliance'],
    'failed_rule': ['data_privacy_compliance'],
    'messages': 'Response cannot be generated as the input fails the checks',
    'reasons': ['Content contains personally identifiable information'],
    'time_taken': 0.156
}

Optional: Use image or audio inputs

Protect natively supports text, image, and audio inputs. Pass your input as a string — the system auto-detects the type.

# Image URL
result = protector.protect(
    "https://example.com/image-sample",
    protect_rules=[{"metric": "content_moderation"}, {"metric": "bias_detection"}],
    action="Image cannot be displayed",
    reason=True,
    timeout=25000
)

# Audio file path
result = protector.protect(
    "/path/to/local/audio.wav",
    protect_rules=[{"metric": "content_moderation"}, {"metric": "bias_detection"}],
    action="Audio content cannot be processed",
    reason=True,
    timeout=25000
)

Supported formats:

  • Images: JPG, PNG, WebP, GIF, BMP, TIFF, SVG — URL, file path, or data URI
  • Audio: MP3, WAV — URL, file path, or data URI
  • Local files are auto-converted to data URIs (max 20 MB). Use direct download URLs, not preview links.

What you can do next

Was this page helpful?

Questions & Discussion