Observability & AnalyticsLegacy Features

LLM Security

Enable robust security measures in your LLM applications to protect against prompt injections, detect anomalies, and prevent data exfiltration.

Legacy / Unsupported. The Cova-LLM-Security-Enabled and Cova-LLM-Security-Advanced request headers were supported by the legacy Cloudflare Worker proxy. They are not read by the current AI Gateway (gateway/src/) and sending them has no effect. This page is retained for historical reference only. See the Header Directory for the list of unsupported headers.

Generative AI is quickly changing the cybersecurity landscape. CoreValue provides built-in security measures powered by Meta's state-of-the-art security models to protect your LLM applications.

Security Implementation

CoreValue's LLM security is powered by two advanced models from Meta:

  1. Prompt Guard (86M): A specialized model for detecting:

    • Direct prompt injections
    • Indirect/embedded malicious instructions
    • Jailbreak attempts
    • Multi-language attacks (supports 8 languages)
  2. Advanced Security Analysis: Optional deeper security analysis using Meta's Llama Guard (3.8B) for comprehensive threat detection across 14 categories:

    CategoryDescription
    Violent CrimesViolence toward people or animals
    Non-Violent CrimesFinancial crimes, property crimes, cyber crimes
    Sex-Related CrimesTrafficking, assault, harassment
    Child ExploitationAny content related to child abuse
    DefamationFalse statements harming reputation
    Specialized AdviceUnauthorized financial/medical/legal advice
    PrivacyHandling of sensitive personal information
    Intellectual PropertyCopyright and IP violations
    Indiscriminate WeaponsCreation of dangerous weapons
    Hate SpeechContent targeting protected characteristics
    Suicide & Self-HarmContent promoting self-injury
    Sexual ContentAdult content and erotica
    ElectionsMisinformation about voting
    Code Interpreter AbuseMalicious code execution attempts

Quick Start

LLM Security currently works with OpenAI models only (gpt-4o, gpt-4o-mini, etc.). Support for other providers is coming soon.

To enable LLM security in CoreValue, simply add Cova-LLM-Security-Enabled: true to your request headers. For advanced security analysis using Llama Guard, add Cova-LLM-Security-Advanced: true:

curl https://gateway.corevalue.dev/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $COVA_API_KEY" \
  -H "Cova-LLM-Security-Enabled: true" \
  -H "Cova-LLM-Security-Advanced: true" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": "How do I enable LLM security with corevalue?"
      }
    ]
}'
from openai import OpenAI
import os

client = OpenAI(
    base_url="https://gateway.corevalue.dev/v1",
    api_key=os.getenv("COVA_API_KEY"),
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "How do I enable LLM security with corevalue?"}],
    extra_headers={
      "Cova-LLM-Security-Enabled": "true",
      "Cova-LLM-Security-Advanced": "true",
    }
)
import { OpenAI } from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.corevalue.dev/v1",
  apiKey: process.env.COVA_API_KEY,
});

const response = await client.chat.completions.create(
  {
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: "How do I enable LLM security with corevalue?" }]
  },
  {
    headers: {
      "Cova-LLM-Security-Enabled": "true",
      "Cova-LLM-Security-Advanced": "true",
    }
  }
);

Security Checks

When LLM Security is enabled, CoreValue:

  • Analyzes each user message using Meta's Prompt Guard model (86M parameters) to detect:
    • Direct jailbreak attempts
    • Indirect injection attacks
    • Malicious content in 8 languages (English, French, German, Hindi, Italian, Portuguese, Spanish, Thai)
  • When advanced security is enabled (Cova-LLM-Security-Advanced: true), activates Meta's Llama Guard (3.8B) model for:
    • Deeper content analysis across 14 threat categories
    • Higher accuracy threat detection
    • More nuanced understanding of context and intent
  • Blocks detected threats and returns an error response:
    {
      "success": false,
      "error": {
        "code": "PROMPT_THREAT_DETECTED",
        "message": "Prompt threat detected. Your request cannot be processed.",
        "details": "See your CoreValue request page for more info."
      }
    }
  • Adds minimal latency to ensure a smooth experience for legitimate requests

Advanced Security Features

  • Two-Tier Protection:
    • Base tier: Fast screening with Prompt Guard (86M parameters)
    • Advanced tier: Comprehensive analysis with Llama Guard (3.8B parameters)
  • Multilingual Support: Detects threats across 8 languages
  • Low Base Latency: Initial screening uses the lightweight Prompt Guard model
  • High Accuracy:
    • Base: Over 97% detection rate on jailbreak attempts
    • Advanced: Enhanced accuracy with Llama Guard's larger model
  • Customizable: Security thresholds can be adjusted based on your application's needs

On this page