Skip to content

Quick Start Guide

Get up and running with elsai Guardrails in minutes.

Basic Usage

Step 1: Import Required Modules

python
from elsai_guardrails.guardrails import LLMRails, RailsConfig

Step 2: Define Configuration

Create a YAML configuration string or file:

python
yaml_content = """
llm:
  engine: "openai"
  model: "gpt-4o-mini"
  api_key: "your-api-key-here"
  temperature: 0.7

guardrails:
  input_checks: true
  output_checks: true
  check_toxicity: true
  check_sensitive_data: true
  check_semantic: true
  toxicity_threshold: 0.7
  block_toxic: true
  block_sensitive_data: true
"""

Step 3: Create Rails Configuration

python
config = RailsConfig.from_content(yaml_content=yaml_content)

Step 4: Initialize LLMRails

python
rails = LLMRails(config=config)

Step 5: Generate with Guardrails

python
messages = [{"role": "user", "content": "Hello, how are you?"}]
result = rails.generate(messages=messages)
print(result)

Complete Example

python
from elsai_guardrails.guardrails import LLMRails, RailsConfig

# Configuration
yaml_content = """
llm:
  engine: "openai"
  model: "gpt-4o-mini"
  api_key: "sk-..."
  temperature: 0.7

guardrails:
  input_checks: true
  output_checks: true
  check_toxicity: true
  check_sensitive_data: true
  check_semantic: true
"""

# Create and use rails
config = RailsConfig.from_content(yaml_content=yaml_content)
rails = LLMRails(config=config)

# Generate response
response = rails.generate(
    messages=[{"role": "user", "content": "What is artificial intelligence?"}]
)
print(response)

Using Configuration File

Instead of YAML strings, you can use a configuration file:

config.yml:

yaml
llm:
  engine: "openai"
  model: "gpt-4o-mini"
  api_key: "your-api-key"
  temperature: 0.7

guardrails:
  input_checks: true
  output_checks: true
  check_toxicity: true
  check_sensitive_data: true
  check_semantic: true
  toxicity_threshold: 0.7
  block_toxic: true
  block_sensitive_data: true

Python code:

python
from elsai_guardrails.guardrails import LLMRails, RailsConfig

config = RailsConfig.from_content(config_path="config.yml")
rails = LLMRails(config=config)

result = rails.generate(
    messages=[{"role": "user", "content": "Hello!"}]
)

New Features

Off-Topic Detection

Keep conversations focused on specific topics:

python
yaml_content = """
llm:
  engine: "openai"
  model: "gpt-4o-mini"
  api_key: "sk-..."

guardrails:
  check_off_topic: true
  block_off_topic: true
  allowed_topics:
    - name: "Customer Support"
      description: "Product questions and customer service"
"""

Learn more about Off-Topic Detection →

SQL Syntax Validation

Validate SQL queries before execution:

python
yaml_content = """
llm:
  engine: "openai"
  model: "gpt-4o-mini"
  api_key: "sk-..."

guardrails:
  check_sql_syntax: true
  sql_dialect: "postgresql"  # or mysql, sqlite, sqlserver, etc.
"""

Learn more about SQL Syntax Validation →

Data Exfiltration Detection (v0.1.5)

Block or mask credential leaks and bulk data exports in LLM output:

python
yaml_content = """
guardrails:
  output_checks: true
  data_exfiltration:
    enabled: true
    action_thresholds:
      warn: 20
      block: 80
"""

Learn more about Data Exfiltration Detection →

ARMS Storage (v0.1.5)

Persist guardrail runs to MongoDB, DynamoDB, or ClickHouse via the ARMS Backend:

python
yaml_content = """
guardrails:
  storage:
    enabled: true
    project: my-app
    arms_correlation: true
"""
bash
export API_BASE_URL=https://your-arms-backend
export ELSAI_ARMS_API_KEY=your-api-key

Learn more about ARMS Storage →

Memory Protection (v0.1.6)

Defend agent memory banks against poisoning at write and retrieval time:

python
yaml_content = """
guardrails:
  memory_guardrails:
    enabled: true
    isolation_scope: session
    ttl_days: 90
    denied_categories_global:
      - credentials
"""
python
from elsai_guardrails.guardrails import LLMRails

rails = LLMRails.from_config("config.yml")
enforcer = rails.guardrail_system.memory_guardrail

result = enforcer.before_write(
    session_id="sess-123",
    writer_id="user-42",
    query="what is the weather in Paris tomorrow",
    reasoning_trace="looking up weather forecast for Paris tomorrow",
    writer_role="analyst",
    content_category="general",
)

if not result.passed:
    print("Memory write blocked:", result.error)

Learn more about Memory Protection →

Agent Trust (v0.1.7)

Defend the boundary between agents in a multi-agent pipeline — identity/trust registry, HMAC attestation, trust-based privilege isolation, and independent re-validation of upstream output:

python
yaml_content = """
guardrails:
  agent_trust:
    enabled: true
    min_trust_level: restricted
    privileged_capabilities:
      delete_production_data: privileged
    agents:
      - agent_id: planner-agent
        trust_level: trusted
        capabilities: [delegate_task, summarize_ticket]
        secret: ${PLANNER_AGENT_SECRET}
      - agent_id: executor-agent
        trust_level: restricted
        capabilities: [execute_tool, summarize_ticket]
        secret: ${EXECUTOR_AGENT_SECRET}
"""
bash
export PLANNER_AGENT_SECRET=$(python -c "import secrets; print(secrets.token_hex(32))")
export EXECUTOR_AGENT_SECRET=$(python -c "import secrets; print(secrets.token_hex(32))")
python
from elsai_guardrails.guardrails import AgentTrustEnforcer
from elsai_guardrails.guardrails.guardrail_policy import GuardrailPolicy

policy = GuardrailPolicy.from_file("config.yml")
enforcer = AgentTrustEnforcer(policy.to_agent_trust_config(), policy.to_agent_registry())
verifier = enforcer.verifier

# Sending agent signs its output
envelope = verifier.sign(
    sender_id="planner-agent",
    recipient_id="executor-agent",
    payload={"response": "Summarize ticket #482."},
    nonce="unique-per-message-nonce",
)

# Receiving agent verifies before consuming it
result = enforcer.verify_message(
    envelope,
    {"response": "Summarize ticket #482."},
    expected_recipient_id="executor-agent",
    required_capability="summarize_ticket",
)

if not result.passed:
    print("Message blocked:", result.error)

Learn more about Agent Trust →

Next Steps

Copyright © 2026 elsai foundry.