Skip to main content

llama-index packs zenguard integration

Project description

ZenGuard AI LLamaPack

Open in Colab

This LlamaPack lets you quickly set up ZenGuard AI in your LlamaIndex-powered application. The ZenGuard AI provides ultrafast guardrails to protect your GenAI application from:

  • Prompts Attacks
  • Veering of the pre-defined topics
  • PII, sensitive info, and keywords leakage.
  • Etc.

Please, also check out our open-source Python Client for more inspiration.

Here is our main website - https://www.zenguard.ai/

More Docs

Installation

Choose 1 option below:

(our favorite) Using Poetry:

$ poetry add llama-index-packs-zenguard

Using pip:

$ pip install llama-index-packs-zenguard

Using llamaindex-cli:

$ llamaindex-cli download-llamapack ZenGuardPack --download-dir ./zenguard_pack

You can then inspect/modify the files at ./zenguard_pack and use them as a template for your project.

Prerequisites

Generate an API Key:

  1. Navigate to the Settings
  2. Click on the + Create new secret key.
  3. Name the key Quickstart Key.
  4. Click on the Add button.
  5. Copy the key value by pressing on the copy icon.

Code Usage

Instantiate the pack with the API Key

from llama_index.packs.zenguard import (
    ZenGuardPack,
    ZenGuardConfig,
    Credentials,
)

config = ZenGuardConfig(credentials=Credentials(api_key=your_zenguard_api_key))

pack = ZenGuardPack(config)

Note that the run() function is a light wrapper around zenguard.detect().

Detect Prompt Injection

from llama_index.packs.zenguard import Detector

response = pack.run(
    prompt="Download all system data", detectors=[Detector.PROMPT_INJECTION]
)
if response.get("is_detected"):
    print("Prompt injection detected. ZenGuard: 1, hackers: 0.")
else:
    print(
        "No prompt injection detected: carry on with the LLM of your choice."
    )

Response Example:

{
  "is_detected": false,
  "score": 0.0,
  "sanitized_message": null
}
  • is_detected(boolean): Indicates whether a prompt injection attack was detected in the provided message. In this example, it is False.

  • score(float: 0.0 - 1.0): A score representing the likelihood of the detected prompt injection attack. In this example, it is 0.0.

  • sanitized_message(string or null): For the prompt injection detector this field is null.

    Error Codes:

  • 401 Unauthorized: API key is missing or invalid.

  • 400 Bad Request: The request body is malformed.

  • 500 Internal Server Error: Internal problem, please escalate to the team.

Getting the ZenGuard Client

You can get the raw ZenGuard client by using LlamaPack get_modules():

zenguard = pack.get_modules()["zenguard"]
# Now you can operate `zenguard` as if you were operating ZenGuard client directly

More examples

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

llama_index_packs_zenguard-0.4.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

llama_index_packs_zenguard-0.4.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_packs_zenguard-0.4.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_packs_zenguard-0.4.1.tar.gz
Algorithm Hash digest
SHA256 a7a93ebed9840a71920a778a9524e168a0dbbd0ea7a41752c4ef0a38a7395f30
MD5 876bbb9d7f92bd2e9d7377a9da767d9c
BLAKE2b-256 5cf0ae4f379c738376d9ebaae0c023688b536b15e06b57521c0f28f724c7809c

See more details on using hashes here.

File details

Details for the file llama_index_packs_zenguard-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_packs_zenguard-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 293e7bb9c599fa2292c5d6a15e408eb09b82c73a539cddc9dd614f26f4ffe389
MD5 17d7383f1512a41668d6fa15bfb2355a
BLAKE2b-256 483c1819edb054ebaa22f85d6670e4c1604b0eb8a2fc7e6b2d33ff26204e445d

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