Introduction


Authentication and API keys

Before you can use the SDK, you'll need two things: an API key and a project ID. These credentials authenticate your application and route your telemetry to the right workspace in TestSavant Studio.

Getting your API key

  1. Sign in to TestSavant Studio at https://app.testsavant.ai
  2. Navigate to API Keys at https://app.testsavant.ai/apikeys
  3. Create a new API key and give it a descriptive name
  4. Copy the key immediately — you won't be able to see it again after closing the dialog
  5. Note your project ID — it's displayed in your project settings
TESTSAVANT_API_KEY=your_api_key_here
TESTSAVANT_PROJECT_ID=your_project_id_here

Then load them in your application:

import os
from testsavant.guard import InputGuard

TESTSAVANT_API_KEY = os.getenv("TESTSAVANT_API_KEY")
TESTSAVANT_PROJECT_ID = os.getenv("TESTSAVANT_PROJECT_ID")

guard = InputGuard(API_KEY=TESTSAVANT_API_KEY, PROJECT_ID=TESTSAVANT_PROJECT_ID)

Observability and Studio integration

Every scan the SDK performs generates structured telemetry that flows into TestSavant Studio—a central control plane where your team can:

  • Review traces and replay user interactions that triggered guardrails
  • Export audit-ready evidence packets for SOC 2, ISO 42001, or GDPR reviews
  • Tune guardrail thresholds based on real production data
  • Create red-team test packs and validate defenses before launch

Studio turns your SDK usage into a continuous assurance loop: test, deploy, observe, adapt.

Core concepts


Scanners

Scanners are modular models that evaluate data against a specific risk or policy.

Input scanners protect what goes into your model:

ScannerDescription
AnonymizeIdentifies and redacts PII like emails, phone numbers, SSNs
BanCodeBlocks code snippets or scripts
BanSubstringsFilters specific banned text patterns
BanTopicBlocks requests about restricted subjects
CodeDetects programming languages in prompts
GibberishStops nonsense prompts from wasting tokens
ImageNSFWScreens images for explicit or unsafe content
ImageTextRedactorRedacts sensitive text from images
InvisibleTextDetects hidden or zero-width characters
LanguageEnforces allowed language requirements
PromptInjectionDetects jailbreak attempts and adversarial prompts
RegexCustom pattern matching for specific use cases
SecretsDetects API keys, tokens, and credentials
SentimentAnalyzes emotional tone of user input
TokenLimitEnforces maximum token counts
ToxicityBlocks hateful, harassing, or unsafe user input

Output scanners protect what comes out of your model:

ScannerDescription
AnonymizeRedacts PII from model responses
BanCodeStrips executable code blocks from outputs
BanSubstringsRemoves banned text patterns from responses
BanTopicKeeps restricted subjects out of completions
BiasFlags biased or unfair statements
FactualConsistencyCompares responses against source material to detect hallucinations
GibberishPrevents meaningless responses
JSONValidates and enforces JSON output format
LanguageEnsures responses match allowed languages
LanguageSameVerifies reply matches customer's input language
MaliciousURLScans for phishing or dangerous links
NoRefusalDetects when the model unnecessarily refuses valid requests
PromptInjectionCatches reflected injection attempts in outputs
ReadingTimeEstimates time required to read the response
RegexCustom pattern matching for output validation
SentimentAnalyzes emotional tone of model responses
ToxicityCatches offensive or harmful language in completions

You can mix and match scanners, set custom thresholds, and combine multiple checks for defense-in-depth.

Guards

A Guard is the orchestrator. You configure guards with your API credentials and project ID, then add the scanners you need.

  • InputGuard validates prompts before they hit your model
  • OutputGuard validates completions before they reach end users

Deployment flexibility

TestSavant SDK works with:

  • LangChain, LlamaIndex, and custom orchestration frameworks
  • Agent workflows, including multi-step reasoning and tool-calling pipelines
  • SaaS, VPC, or on-prem deployments with customer-managed keys and regional data residency

You can run guardrails synchronously for real-time chat or asynchronously for batch processing and background agents.


What's next

Ready to integrate guardrails into your AI stack? Here's where to go: