Skip to main content

Open-source guardrail engine for LLM applications

Project description

open-guardrail (Python)

Open-source guardrail engine for LLM applications. Zero dependencies. Pure Python.

PyPI Python License

Install

pip install open-guardrail

Quick Start

from open_guardrail import pipe, prompt_injection, pii, keyword

pipeline = pipe(
    prompt_injection(action="block"),
    pii(entities=["email", "phone"], action="mask"),
    keyword(denied=["hack", "exploit"], action="block"),
)

result = pipeline.run("user input text here")
if not result.passed:
    print(f"Blocked: {result.action}")
# result.output contains masked text when PII is detected

24 Built-in Guards

Guard Description
prompt_injection Jailbreak and prompt injection detection
sql_injection SQL injection (3 sensitivity levels)
xss_guard Cross-site scripting detection + sanitize
secret_pattern Credentials, API keys, connection strings
invisible_text Zero-width/bidi unicode detection
canary_token System prompt leakage detection
pii Email, phone, SSN, passport, ITIN, Medicare
pii_kr Korean PII (주민등록번호, 여권, 면허 등)
pii_jp Japanese PII (マイナンバー, パスポート 등)
pii_cn Chinese PII (身份证, 护照, 手机号 등)
keyword Deny/allow keyword lists
toxicity Profanity, hate, threats, harassment
profanity_kr Korean profanity (초성 + 변형)
profanity_jp Japanese profanity (ひらがな/カタカナ/漢字)
profanity_cn Chinese profanity (pinyin abbreviations)
gibberish_detect Nonsensical input detection
no_refusal LLM refusal response detection
ban_code Code block detection (7 languages)
ban_substring Substring blocking
valid_range Number range validation
valid_choice Valid choice validation
readability Flesch Reading Ease score
reading_time Reading time estimation
word_count Word/character limits

Guard Composition

from open_guardrail import compose, when, parallel

# Bundle guards
security = compose("security",
    prompt_injection(action="block"),
    sql_injection(action="block"),
)

# Conditional execution
long_text_check = when(lambda t: len(t) > 200, toxicity(action="block"))

# Parallel execution
fast = parallel(prompt_injection(action="block"), toxicity(action="block"))

License

MIT

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

open_guardrail-0.2.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

open_guardrail-0.2.0-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

Details for the file open_guardrail-0.2.0.tar.gz.

File metadata

  • Download URL: open_guardrail-0.2.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for open_guardrail-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e98b18cbf50c0071b6965a2a9a724b913ad782f830d906bc93fadff371d5840a
MD5 90e348360e020c4cf050933d03c19245
BLAKE2b-256 3aa5526e221c0d8b58021504e26bb09d49e30f1231ae2d0f6c30f3d7fc38f934

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_guardrail-0.2.0.tar.gz:

Publisher: publish-python.yaml on wonjangcloud9/open-guardrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file open_guardrail-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: open_guardrail-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 37.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for open_guardrail-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f13cd75f3aa6ac58a5e373daf7a5abe1590d943865f9bcaff88885fec0669779
MD5 197c04f94dc5bf099c4d6ba77f085ae3
BLAKE2b-256 935cc05a6fc9263538d7c7a5f8c8d24f6253140dcce21d561ddad98b7157fad1

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_guardrail-0.2.0-py3-none-any.whl:

Publisher: publish-python.yaml on wonjangcloud9/open-guardrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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