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.1.0.tar.gz (20.2 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.1.0-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: open_guardrail-0.1.0.tar.gz
  • Upload date:
  • Size: 20.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 e5097ff69c201f30b2027b3530c85a11a34efe92d4b0dd7016348e1b953cfcb8
MD5 ff8a212cee7a04c0fcdd91df066ba2b2
BLAKE2b-256 1e00bd520f81cca1126ba1bd282c5f3945b9891308afd4e3ff8454012b92ad67

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_guardrail-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: open_guardrail-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 35.3 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34f10edfb64bb480cb64ad0c70603f88e7fa195de822f7276257008816ffd393
MD5 e641bda19e3f14a03134f75c2c956ced
BLAKE2b-256 c6c97f5ecc1a25b30a91ef5726e0f0eb145ab3cc0beaf0d3ecf11716fae4b4b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_guardrail-0.1.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