Open source · Self-hosted

Stop prompt injection before it reaches your LLM

Guard Spec is a gateway between your apps and any OpenAI-compatible API. It checks prompts, retrieved documents, tool results and MCP tools on the way in, and the model's answer on the way out. Prompts never leave your network.

  • Apache-2.0
  • Go
  • English · Tiếng Việt
  • v0.1 · pre-1.0
app.py
from openai import OpenAI

client = OpenAI(
    # was https://api.openai.com/v1
    base_url="http://guard-spec:8080/v1",
    api_key=GUARD_SPEC_KEY,
)
# the rest of your code stays the same
when a request carries an injection
HTTP 400
{"error": {
  "code": "content_filter",
  "message": "Request blocked: prompt
              injection detected."}}
# the LLM is never called
Works with
The problem

Your LLM reads text that you did not write

Chatbots, RAG assistants and agents pass user input, web pages, documents and tool output straight into the model. Any of them can carry instructions that override yours.

Direct injection

A user types “ignore your previous instructions” in a hundred disguises: leetspeak, homoglyphs, Vietnamese teencode, text without diacritics.

Indirect injection

A web page, email or PDF in your knowledge base hides an instruction in invisible HTML, Unicode tag characters or bidi tricks.

Tool poisoning

An MCP server describes a tool with hidden steps that tell your agent to read secrets and send them elsewhere.

How it works

One gateway in front of every LLM call

Point your SDK's base URL at Guard Spec. Every request is sanitized, scored by three detection layers and checked against your policies. Clean requests go on; injections get a 400 and an alert.

Guard Spec between your AI apps and the LLM providers
  1. L0

    Sanitizer

    Strips invisible characters, Unicode tags and bidi overrides; flags anomalies.

  2. L1

    Rules

    Fast pattern rules that see through diacritics, teencode, leetspeak and homoglyphs.

  3. L2

    Classifier

    Our own ONNX model, trained for English and Vietnamese, running in process.

  4. L3

    Similarity

    Embedding match against known attack exemplars you can add to.

  5. CEL

    Policies

    Per-organization rules compiled to CEL: allow, block, log or route.

  6. OUT

    Output guard

    Catches exfiltration links, personal data and a leaked canary, also when streaming.

Features

Everything a security team needs around the detector

Three layers, one score

Rules, a classifier and similarity search are fused into one score with a clear threshold. Run rules only, or all three.

English and Vietnamese

Built and evaluated for both, including Vietnamese with and without diacritics, teencode and leetspeak.

Self-hosted, private

Runs in your network. No prompt goes to a third-party moderation API. Every rule is readable and editable.

OpenAI-compatible routing

Change one base URL. Route to OpenAI, Azure OpenAI, Anthropic, Gemini, vLLM or Ollama per organization and project.

Real-time alerts

Blocked requests reach Slack, Microsoft Teams, Telegram, email, signed SIEM webhooks or a SOC agent over A2A.

SSO and 2FA

OpenID Connect single sign-on (Entra ID, Okta, Google, Keycloak), TOTP two-factor, org-wide login rules.

Multi-tenant

Organizations, projects, roles and API keys with rate limits, backed by Postgres row-level security.

Audit trail

One row per request (content off by default) and a log of every configuration and security change.

Ready to deploy

Docker Compose, a Helm chart and an air-gapped image. Signed images, SBOMs, Prometheus and OpenTelemetry.

Admin UI

See every decision, change every rule

A bilingual admin console for the security team, in light and dark.

  • Dashboard and live request flow through each layer
  • Policy editor, as text or visual, with a simulator
  • Providers, routing, request log and audit
  • Alert rules, channels, members and security settings
Guard Spec admin UI showing the request flow
Benchmarks

Measured, published, reproducible

All three layers with the default classifier, on our eval set of 2,176 rows (1,171 attacks, 1,005 benign; 926 English, 1,250 Vietnamese).

0.986ROC AUC
93.2%attacks blocked at the default threshold
1.4%benign requests blocked
3.7 msmedian detector latency per request

Measured on 2026-11-04 on an Apple M3 Max; latency is the detector in process, not end-to-end HTTP. The Vietnamese data is synthetic, and benign Vietnamese teencode is still blocked 3.5% of the time. The README lists every number, its limits and the commands to reproduce it.

Compared with

Where Guard Spec fits

Kind of toolExamplesGuard Spec
Python guardrail librariesGuardrails AI, NeMo Guardrails, LLM GuardA network service in front of the model: any language can use it, and you change a base URL, not your code
Hosted detection APIsLakera Guard, Azure AI Prompt ShieldsSelf-hosted: prompts never leave your network, and you can read and change every rule
Standalone classifiersPrompt Guard, ProtectAI DeBERTaIts own classifier is one of several layers, with sanitization, policies, an output guard and an audit log around it
Quick start

Running in five minutes

You need Docker with Compose v2. One script writes strong random secrets, pulls the signed images and the models (SHA-256 verified), and waits until all three layers are ready.

terminal
$ git clone https://github.com/guard-spec/guard-spec.git
$ cd guard-spec
$ scripts/quickstart.sh
# writing .env with random secrets
# pulling models (≈270 MB, SHA-256 verified)
ready: {"layers":["l1","l2","l3"]}

Put a guard in front of your LLM

Free and open source under Apache-2.0. Star the repo, try it on your own traffic, and tell us what it misses.