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
- 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.
Release files for llama-index-guardrails-icephi 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llama_index_guardrails_icephi-0.1.1.tar.gz | 3.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama_index_guardrails_icephi-0.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 7.2 kB
Release files / llama_index_guardrails_icephi-0.1.1.tar.gz
| Download URL | llama_index_guardrails_icephi-0.1.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
595c36ead36dc462fc57daa7685a04cbfb3e17ad632fba5752ace71ebe0fc1f1
|
|
BLAKE2b-256 checksum How to use checksums |
5a08cc8f331d10c3de9276d0d0a4da08b34200b02bce2751686a2835168428ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / llama_index_guardrails_icephi-0.1.1-py2.py3-none-any.whl
| Download URL | llama_index_guardrails_icephi-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f4182a62cd95e9c34e42037fdc1383eb34fc63af40a2d8e4ad0222fc19c52f32
|
|
BLAKE2b-256 checksum How to use checksums |
f3f6e5fa6c3ec3ac414c366985b8100b5d78b236c5bbaf9aabde57de2374eb0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|