Skip to main content

Official Python SDK for the Gjallarhorn prompt-injection detection API

Project description

gjallarhorn-sdk

Official Python SDK for the Gjallarhorn prompt-injection detection API.

PyPI version License: MIT

Installation

pip install gjallarhorn-sdk

Requirements: Python 3.9+, httpx.

Quickstart

from gjallarhorn_sdk import GjallarhornClient

client = GjallarhornClient("gjh_your_api_key_here")

result = client.scan(user_input)
if result.should_block:
    raise ValueError("Injection detected")
# safe to send to LLM

Async usage

import asyncio
from gjallarhorn_sdk import AsyncGjallarhornClient

async def main():
    async with AsyncGjallarhornClient("gjh_...") as client:
        result = await client.scan("some user input")
        print(result.risk_level, result.detection_layers)

asyncio.run(main())

Methods

Method Description
scan(content, *, use_classifier?, context?) Scan text for prompt injection
scan_multimodal(file, mime_type, filename?) Scan PDF/image/QR code
get_quota() Get credit usage and quota
check_canary(llm_response) Check for canary token in LLM output

Both GjallarhornClient (sync) and AsyncGjallarhornClient (async) have the same methods.

Scan a PDF

from pathlib import Path

result = client.scan_multimodal(Path("user-upload.pdf"), "application/pdf")
print(result.risk_level, result.billed_pages)

Error handling

from gjallarhorn_sdk import (
    AuthError, QuotaExceededError, RateLimitError,
    ExtractionFailedError, ServiceUnavailableError,
)

try:
    result = client.scan(user_input)
except AuthError:
    print("Invalid API key")
except QuotaExceededError:
    print("Monthly quota hit")
except RateLimitError as e:
    print(f"Rate limited — retry after {e.retry_after}s")
except ExtractionFailedError:
    print("Could not extract file content")

The SDK retries automatically on rate-limit (respecting retry_after) and 503 errors (exponential backoff, max 3 retries).

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

gjallarhorn_hq_sdk-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

gjallarhorn_hq_sdk-1.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file gjallarhorn_hq_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: gjallarhorn_hq_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for gjallarhorn_hq_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ae76e45927b1fabdcf6774854aafcf378a1900c81fba49f4285ba6b4b26ae33a
MD5 b8db53971309cf3c825c1095e7788be1
BLAKE2b-256 e0402c6378c8d285b4c9cc345d0e1fd14340be1d1bf9b8e6632e7f2558a59e65

See more details on using hashes here.

File details

Details for the file gjallarhorn_hq_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gjallarhorn_hq_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cecbdec32da94853a444944f037f399a7da169237c710343b60d1832490692b
MD5 086143356a8e2392609e169ea2c3ee33
BLAKE2b-256 ac0f4412e6254a00cc3596e180ddbe844480aaa5d72035e4fbe17fddfc16cfc9

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