Skip to main content

llama-index-guardrails-icephi

Sub-20ms prompt injection and jailbreak protection for LlamaIndex query engines, powered by Ice Phi.

llama-index-guardrails-icephi provides a custom NodePostprocessor (IcePhiPromptGuard) that inspects retrieved nodes and user queries before they hit your LLM or retrieval pipeline, automatically blocking malicious prompts, jailbreak attempts, and prompt injection attacks in real time. Installation

pip install llama-index-guardrails-icephi Quick Start

  1. Set your API Key

Set your Ice Phi API key as an environment variable:

export ICEPHI_API_KEY="your-icephi-api-key"

Or pass it directly when initializing the postprocessor. 2. Add Guardrails to Your Query Engine

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader from llama_index.guardrails.icephi import IcePhiPromptGuard Load documents and create an index

documents = SimpleDirectoryReader("./data").load_data() index = VectorStoreIndex.from_documents(documents) Initialize the Ice Phi guardrail

icephi_guard = IcePhiPromptGuard( api_key="your-icephi-api-key", # Optional if ICEPHI_API_KEY env var is set raise_on_blocked=True # Raises ValueError if a prompt injection is detected ) Attach the guardrail as a node postprocessor

query_engine = index.as_query_engine( node_postprocessors=[icephi_guard] ) Safe query execution

try: response = query_engine.query("Summarize the document.") print(response) except ValueError as e: print(f"Blocked by Ice Phi Guardrail: {e}") Configuration Options

The IcePhiPromptGuard accepts the following parameters:

api_key (Optional[str]): Ice Phi API Key. Defaults to reading ICEPHI_API_KEY from environment variables.

api_url (str): Ice Phi Shield API endpoint (default: "https://api.icephi.com/shield").

raise_on_blocked (bool): If True, raises ValueError on detected attacks. If False, filters out flagged nodes cleanly. Default is True.

timeout (float): Request timeout in seconds (default: 2.0).

Features

Sub-20ms Latency: High-throughput, optimized ONNX inference endpoint.

Comprehensive Defense: Protects against direct prompt injections, jailbreaks, and indirect prompt injection vectors inside retrieved contexts.

Native LlamaIndex Integration: Implements BaseNodePostprocessor for seamless placement in RAG and Agent pipelines.

License

This project is licensed under the MIT License.

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_guardrails_icephi-0.1.1.tar.gz (3.2 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_guardrails_icephi-0.1.1-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file llama_index_guardrails_icephi-0.1.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_guardrails_icephi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 595c36ead36dc462fc57daa7685a04cbfb3e17ad632fba5752ace71ebe0fc1f1
MD5 bd073fb0e5ea306f0930ac25a19a274c
BLAKE2b-256 5a08cc8f331d10c3de9276d0d0a4da08b34200b02bce2751686a2835168428ea

See more details on using hashes here.

File details

Details for the file llama_index_guardrails_icephi-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_guardrails_icephi-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f4182a62cd95e9c34e42037fdc1383eb34fc63af40a2d8e4ad0222fc19c52f32
MD5 de14d399fc0a9b0e302cc1f45c8163f1
BLAKE2b-256 f3f6e5fa6c3ec3ac414c366985b8100b5d78b236c5bbaf9aabde57de2374eb0e

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 Sentry Error logging StatusPage Status page