Skip to main content

Security guards for LLM-powered and agentic AI applications. Zero dependencies. Covers OWASP Top 10 for LLMs 2025.

Project description

llm-trust-guard

Security guards for LLM-powered applications. Zero dependencies. Python port of the npm package.

Installation

pip install llm-trust-guard

Quick Start

from llm_trust_guard import InputSanitizer, EncodingDetector, CompressionDetector

# Check for prompt injection
sanitizer = InputSanitizer(threshold=0.3)
result = sanitizer.sanitize(user_input)
if not result.allowed:
    print(f"Blocked: {result.matches}")

# Check for encoding bypass attacks
encoder = EncodingDetector()
result = encoder.detect(user_input)
if not result.allowed:
    print(f"Encoded threat: {result.violations}")

# Check structural similarity to known attacks (NCD)
detector = CompressionDetector()
result = detector.detect(user_input)
if not result.allowed:
    print(f"Similar to: {result.ncd_analysis.closest_category}")

Guards (Phase 1)

Guard Purpose Method
InputSanitizer Prompt injection detection (170+ patterns, 11 languages) Regex + PAP
EncodingDetector Encoding bypass (9 formats: Base64, URL, Unicode, Hex, HTML, ROT13, Octal, Base32) Decode + scan
CompressionDetector Structural similarity to known attacks gzip NCD (135 templates)
HeuristicAnalyzer Synonym expansion + structural + statistical analysis 8 attack categories
OutputFilter PII/secret detection and masking in LLM output Regex + redaction

Key Features

  • Zero dependencies — only Python stdlib (re, zlib, base64, html)
  • Same patterns as the npm package — feature parity with llm-trust-guard v4.13.1
  • Fast — all checks complete in <5ms
  • Python 3.9+ compatible

More Guards Coming

The npm package has 31 guards total. Python Phase 2 will add:

  • ExternalDataGuard, AgentSkillGuard, SessionIntegrityGuard
  • SchemaValidator, ToolResultGuard, TokenCostGuard

Links

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

llm_trust_guard-0.2.2.tar.gz (124.3 kB view details)

Uploaded Source

Built Distribution

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

llm_trust_guard-0.2.2-py3-none-any.whl (143.0 kB view details)

Uploaded Python 3

File details

Details for the file llm_trust_guard-0.2.2.tar.gz.

File metadata

  • Download URL: llm_trust_guard-0.2.2.tar.gz
  • Upload date:
  • Size: 124.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for llm_trust_guard-0.2.2.tar.gz
Algorithm Hash digest
SHA256 66138483c46be70175d7e0c6f31a24b9f299c8662adef726218e6324a035bb5e
MD5 580ddfd34c5f5ae21edbeb4dc3669f98
BLAKE2b-256 47c6ab9e8b73a368b0c178a343e84554ef96de9e3320d2b4c38015450912e5a2

See more details on using hashes here.

File details

Details for the file llm_trust_guard-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_trust_guard-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5fcc3933bae00baf8be55b1e1b9c15f6dc0f48ba850097c577f9b8f4e6c1b20b
MD5 8bbd2fb49ed325b792f7ea37782fb0d7
BLAKE2b-256 22f815921dddcde9ff8151e08ee82d07aabd0c67a290ec44934d471daee03f3f

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