Skip to main content

Implementation Guide

Follow these steps to integrate SecureAI Guard into your application

1. Get access to the SecureAI Guard package

SecureAI Guard is not yet published to public package registries.

SecureAI Guard runs as a proxy or as an in-process middleware between your application and the model provider. It sees the full request — system prompt, retrieved context, user turn and tool definitions — before the call leaves your network, and it sees the completion before your application acts on it. Both halves matter: most of the controls below are output-side, and an input-only filter cannot enforce them.

The client library and the container image are distributed directly to customers and evaluation accounts. There is no public npm, PyPI or Docker Hub namespace to install from today, and any package you find under those names is not ours.

The client library and container image are distributed directly to customers and evaluation accounts, not from a public npm, PyPI or Docker Hub namespace. Access credentials and the private registry endpoint are issued once an evaluation or enterprise agreement is in place.

Request early access

The configuration and integration examples in the following steps show the real API and are accurate today.

2. Configure the guard for your environment

Configure SecureAI Guard with your settings and API keys.

Configuration declares three things: which models the application is allowed to call, which detectors run on each request, and what happens when one fires. Keep the allow-list explicit. An unbounded model list is how a cost incident and a data-residency incident both start — a request routed to a provider you never reviewed is a transfer to a processor you never assessed.

Start in report-only mode. Run the detectors, record what they would have blocked, and read a week of that traffic before you turn enforcement on. Every guardrail has a false-positive rate, and the only way to learn yours is against your own prompts.

Basic setup

import { SecureAIGuard } from '@secureaiguard/core'; const config = { apiKey: 'your-api-key', environment: 'production', monitoring: { enabled: true, logLevel: 'info' } }; const guard = new SecureAIGuard(config);

Advanced setup

const advancedConfig = { apiKey: 'your-api-key', environment: 'production', monitoring: { enabled: true, logLevel: 'debug', customMetrics: ['promptInjection', 'dataLeakage'], }, security: { enableAuditLog: true, maxTokens: 1000, allowedModels: ['gpt-3.5-turbo', 'gpt-4'], contentFiltering: { enabled: true, level: 'strict' } }, rateLimit: { enabled: true, maxRequests: 100, windowMs: 60000 } };

3. Wrap the model call on both the input and the output side

Implement security measures in your application.

Place the guard on the server, on the path between your application and the provider. A control that runs in the browser is advice, not enforcement — the client can be modified and the provider endpoint called directly.

The output-side call is the one teams skip, and it is the one that stops the OWASP LLM05 (Improper Output Handling) class: treat a completion exactly as you would treat any other untrusted string before it reaches a shell, a SQL statement, a template, a browser or an HTTP client. Rendering model output as HTML without escaping is stored XSS with extra steps.

Express.js middleware

import express from 'express'; import { SecureAIGuard } from '@secureaiguard/core'; const app = express(); const guard = new SecureAIGuard(config); app.post('/api/ai/generate', guard.middleware(), async (req, res) => { try { // Validate and secure the input const secureInput = await guard.validateInput(req.body); // Process with your AI model const result = await aiModel.generate(secureInput); // Validate the output const secureOutput = await guard.validateOutput(result); res.json({ result: secureOutput }); } catch (error) { guard.handleError(error); res.status(400).json({ error: error.message }); } });

Next.js API route

// pages/api/ai/generate.js import { SecureAIGuard } from '@secureaiguard/core'; const guard = new SecureAIGuard(config); export default guard.withApiRoute(async function handler(req, res) { if (req.method !== 'POST') { return res.status(405).json({ message: 'Method not allowed' }); } try { const secureInput = await guard.validateInput(req.body); const result = await aiModel.generate(secureInput); const secureOutput = await guard.validateOutput(result); return res.json({ result: secureOutput }); } catch (error) { guard.handleError(error); return res.status(400).json({ error: error.message }); } });

4. Turn on monitoring, alerting and an audit trail

Set up monitoring and analytics for your security implementation.

The question an incident review always asks is "what was in the model’s context window at the time?", and it is unanswerable unless you decided in advance to record it. Log the resolved prompt, the retrieved documents and their sources, the tool calls attempted, the detector verdicts and the model and version that served the request.

Prompt and completion bodies are frequently personal data and frequently commercially sensitive, so treat the log store as a production data store: access-controlled, retention-bounded, and in a region you have actually decided on. Recording everything forever into an unrestricted index is a breach waiting for an audience.

Basic monitoring

// Set up basic monitoring guard.monitoring.setup({ metrics: ['requests', 'threats', 'latency'], dashboard: { port: 3000, path: '/metrics' } });

Advanced monitoring with alerts

// Set up advanced monitoring with alerts guard.monitoring.setup({ metrics: ['requests', 'threats', 'latency', 'tokenUsage'], dashboard: { port: 3000, path: '/metrics', customWidgets: ['threatMap', 'usageStats'] }, alerts: { enabled: true, channels: ['email', 'slack'], thresholds: { threats: { warning: 5, critical: 10 }, errorRate: { warning: 0.01, critical: 0.05 } }, notifications: { slack: { webhook: 'your-slack-webhook', channel: '#security-alerts' }, email: { to: ['security@yourdomain.com'], from: 'alerts@secureaiguard.com' } } }, logging: { level: 'debug', format: 'json', storage: { type: 'elasticsearch', config: { node: 'http://localhost:9200' } } } });

Next

The controls above bound the damage from a successful attack; they do not eliminate the attack class. If you are working out what is actually enforceable in your deployment, start with what prompt injection is and why filtering does not close it, then read what SecureAI Guard inspects and enforces. For deployment models that keep prompt content inside your own network, see on-premises deployment.