Skip to main content

Panoptica GenAI Protection SDK

A simple python client SDK for integration with Panoptica GenAI Protection.


GenAI Protection is part of Panoptica, a cloud native application protection platform (CNAPP), and provides protection for LLM-backed systems. Specifically, the GenAI Protection SDK inspects both input and output prompts, flagging those it identifies as likely containing malicious content with a high degree of certainty.

The Python SDK is provided to programmatically integrate your system with our LLM protection software, enabling you to verify the safety level of processing a user requested prompt before actually processing it. Following this evaluation, the application can then determine the appropriate subsequent steps based on your policy.

Installation

pip install panoptica_genai_protection

Usage Example

Working assumptions:

  • You have generated a key-pair for GenAI Protection in the Panoptica settings screen
    • The access key is set in the GENAI_PROTECTION_ACCESS_KEY environment variable
    • The secret key is set in the GENAI_PROTECTION_SECRET_KEY environment variable
  • We denote the call to generating the LLM response as get_llm_response()

GenAIProtectionClient provides the check_llm_prompt method to determine the safety level of a given prompt.

Sample Snippet

from panoptica_genai_protection.client import GenAIProtectionClient
from panoptica_genai_protection.gen.models import Result as InspectionResult

# ... Other code in your module ...

# initialize the client
genai_protection_client = GenAIProtectionClient()

# Send the prompt for inspection BEFORE sending it to the LLM
inspection_result = genai_protection_client.check_llm_prompt(
  chat_request.prompt,
  api_name="chat_service",  # Name of the service running the LLM
  api_endpoint_name="/chat",  # Name of the endpoint serving the LLM interaction
  sequence_id=chat_id,  # UUID of the chat, if you don't have one, provide `None`
  actor="John Doe",  # Name of the "actor" interacting with the LLM service.
  actor_type="user",  # Actor type, one of {"user", "ip", "bot"}
)

if inspection_result.result == InspectionResult.safe:
  # Prompt is safe, generate an LLM response
  llm_response = get_llm_response(
    chat_request.prompt
  )

  # Call GenAI protection on LLM response (completion)
  inspection_result = genai_protection_client.check_llm_response(
    prompt=chat_request.prompt,
    response=llm_response,
    api_name="chat_service",
    api_endpoint_name="/chat",
    actor="John Doe",
    actor_type="user",
    request_id=inspection_result.reqId,
    sequence_id=chat_id,
  )
  if inspection_result.result != InspectionResult.safe:
    # LLM answer is flagged as unsafe, return a predefined error message to the user
    answer_response = "Something went wrong."
else:
  # Prompt is flagged as unsafe, return a predefined error message to the user
  answer_response = "Something went wrong."

Async use:

You may use the client in async context in two ways:

async def my_async_call_to_gen_ai_protection(prompt: str):
    client = GenAIProtectionClient(as_async=True)
    return await client.check_llm_prompt_async(
        prompt=prompt,
        api_name="test",
        api_endpoint_name="/test",
        actor="John Doe",
        actor_type="user"
    )

or

async def my_other_async_call_to_gen_ai_protection(prompt: str):
    async with GenAIProtectionClient() as client:
      return await client.check_llm_prompt_async(
          prompt=prompt,
          api_name="test",
          api_endpoint_name="/test",
          actor="John Doe",
          actor_type="user"
      )

Metadata

Release files for panoptica-genai-protection 0.1.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for panoptica-genai-protection 0.1.18
File Size Uploaded
panoptica_genai_protection-0.1.18.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for panoptica-genai-protection 0.1.18
File Interpreter ABI Platform
panoptica_genai_protection-0.1.18-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / panoptica_genai_protection-0.1.18.tar.gz

Download URL panoptica_genai_protection-0.1.18.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9f7e5ba12f47d2790691bb13a86400d64c786512ff4f2cd76a49443bab5ad032
BLAKE2b-256 checksum
How to use checksums
faca390903110b254cfad29b218786025452eb0639a43a8be6353b3124cfc6e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Release files / panoptica_genai_protection-0.1.18-py3-none-any.whl

Download URL panoptica_genai_protection-0.1.18-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c0f9237cf10d6d4c9d4524cc62768531e997a6e4eeb8996b8ec3d07a239b202
BLAKE2b-256 checksum
How to use checksums
6dc70a8270b536532fd2c2ca4f922e2cb66f319e3f318e99ee3b11104afa3b07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page