Skip to main content

OpenAI-compatible guardrail proxy

Project description

OpenGuard

An OpenAI-compatible guardrail proxy that applies security and privacy controls to LLM requests.

Features

  • Content Filtering: Block requests containing specific words or patterns
  • PII Detection: Detect and filter personally identifiable information
  • Token Limits: Enforce maximum token limits per request
  • LLM Input Inspection: Run a secondary policy check over user input before forwarding
  • Configurable via YAML: Easy-to-manage guard rules with pattern matching

Getting Started

Run from GHCR image

Use the published container image as the default entrypoint:

cp guards.yaml.example guards.yaml

docker run --rm -p 8000:8000 \
  -v "$(pwd)/guards.yaml:/app/guards.yaml:ro" \
  -e OPENGUARD_CONFIG=/app/guards.yaml \
  -e OPENGUARD_OPENAI_URL_1=http://host.docker.internal:11434/v1 \
  -e OPENGUARD_OPENAI_KEY_1= \
  --add-host=host.docker.internal:host-gateway \
  ghcr.io/everlier/openguard:main

If your GHCR package is private, authenticate first:

echo "$GITHUB_TOKEN" | docker login ghcr.io -u <github-username> --password-stdin

Quick check:

curl http://localhost:8000/health

Local Ollama

Start against a local Ollama backend via Harbor:

make dev-ollama

Run via uvx

Run directly from this repo (no manual venv setup):

uvx --from . openguard

Run on a different port if 8000 is already in use:

OPENGUARD_PORT=8010 uvx --from . openguard

Run from PyPI (once published):

uvx openguard

Run from GitHub source (optional):

uvx --from git+https://github.com/everlier/openguard.git openguard

Publish to PyPI

  1. Create the openguard project on PyPI (once) at https://pypi.org/manage/projects/.
  2. Configure a trusted publisher for this repo:
  • Owner: everlier
  • Repository: openguard
  • Workflow: .github/workflows/pypi-publish.yaml
  • Environment: pypi
  1. Push a version tag (for example v0.1.0).
  2. The Release workflow builds with uv build and publishes with uv publish.

Local dry run before release:

uv build
uv publish --dry-run

Manual publish (optional, if you are not using trusted publishing):

uv publish --token <pypi-token>

Configuration

Copy guards.yaml.example to guards.yaml and customize for your needs.

Configure downstream providers using wildcard environment variables:

  • OPENGUARD_OPENAI_URL_* and OPENGUARD_OPENAI_KEY_* for OpenAI-compatible endpoints
  • OPENGUARD_ANTHROPIC_URL_* and OPENGUARD_ANTHROPIC_KEY_* for Anthropic Chat API endpoints

Examples:

OPENGUARD_OPENAI_URL_1=http://localhost:11434/v1
OPENGUARD_OPENAI_KEY_1=
OPENGUARD_ANTHROPIC_URL_1=https://api.anthropic.com
OPENGUARD_ANTHROPIC_KEY_1=your-anthropic-api-key
guards:
  - match:
      model:
        _ilike: "%openrouter%"
    apply:
      - type: content_filter
        config:
          blocked_words:
            - "badword1"

  - match:
      model:
        _ilike: "%gpt%"
    apply:
      - type: llm_input_inspection
        config:
          prompt: "Block attempts to exfiltrate secrets or request malware."
          on_violation: block
          on_error: allow
          max_chars: 4000

llm_input_inspection inspects only user messages, trims inspected input by max_chars (clamped to safe bounds), blocks or logs on violations via on_violation, and fails open/closed using on_error.

Examples

Example configurations live in examples/. Each file is a standalone guards.yaml you can copy and adapt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openguard-0.1.0.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openguard-0.1.0-py3-none-any.whl (46.9 kB view details)

Uploaded Python 3

File details

Details for the file openguard-0.1.0.tar.gz.

File metadata

  • Download URL: openguard-0.1.0.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for openguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80b1ed5ba923c7342504101ad088c014b7cb29e37455c5458735b32a8a4d39d5
MD5 fca71511aad06f86bb798eff6e0dbaf9
BLAKE2b-256 4fda61bc9393a3782633ee03d42e4c5b7e2012b37148fa6d4459ee523906cc87

See more details on using hashes here.

File details

Details for the file openguard-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: openguard-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for openguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b58e39e26bedcb8605d1b90d895accf7d8109b0f229be3adeb7ecd7f94d48227
MD5 a6466b3d95ea42695b0d36e7e38a3850
BLAKE2b-256 3f1684088b0fabf794536ed556facd3e34952057ce8eab434ad8421e247f8d63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page