Prompt injection firewall for LLM agents. Scan tool outputs and user messages before they reach your model.
Project description
benchspan
Prompt injection firewall for LLM agents. One-line integration that scans tool outputs and user messages before they reach your model.
Install
pip install benchspan
Quick Start
from benchspan import BenchGuard
guard = BenchGuard(api_key="ag_live_...", agent="my-agent")
# Direct scan
result = guard.scan("some tool output", role="tool")
# result.injection -> True/False
# result.verdict -> "block", "warn", or "pass"
Framework Integrations
LangChain / CrewAI
from benchspan import BenchGuard
from langchain_anthropic import ChatAnthropic
guard = BenchGuard(api_key="ag_live_...")
llm = ChatAnthropic(model="claude-sonnet-4-6")
result = llm.invoke(messages, config={"callbacks": [guard]})
OpenAI Agents SDK
from benchspan import BenchGuard
from agents import Agent, Runner
guard = BenchGuard(api_key="ag_live_...")
agent = Agent(name="assistant", model="gpt-4o", hooks=guard.as_agent_hooks())
result = await Runner.run(agent, input="Hello")
Google ADK
from benchspan import BenchGuard
from google.adk.agents import LlmAgent
guard = BenchGuard(api_key="ag_live_...")
agent = LlmAgent(
name="assistant",
model="gemini-2.5-pro",
before_model_callback=guard.as_adk_callback(),
)
Raw OpenAI / Anthropic SDK
from benchspan import BenchGuard
from openai import OpenAI
guard = BenchGuard(api_key="ag_live_...")
client = OpenAI()
@guard.wrap
def call_llm(messages):
return client.chat.completions.create(model="gpt-4o", messages=messages)
result = call_llm(messages)
Modes
"block"(default) -- Waits for scan result. RaisesInjectionDetectedErrorif injection detected."warn"-- Fires scan in the background with zero added latency. Logs a warning if injection detected but never blocks.
# Production -- block injections
guard = BenchGuard(api_key="ag_live_...", mode="block")
# Evaluation -- monitor without blocking
guard = BenchGuard(api_key="ag_live_...", mode="warn")
How It Works
- Framework hook fires before each LLM call
- SDK scans
userandtoolmessages via the BenchSpan API systemandassistantmessages are skipped (trusted)- Already-scanned messages are deduplicated across multi-turn conversations
- In block mode,
InjectionDetectedErroris raised if injection detected - In warn mode, the scan runs async -- zero latency added to your agent
Links
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
benchspan-0.3.0.tar.gz
(12.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file benchspan-0.3.0.tar.gz.
File metadata
- Download URL: benchspan-0.3.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5e8f3ba4f5a493bef80cfd262ba6be44f850b5c125a418cbd91ba217b99c5e9
|
|
| MD5 |
f42a9c55647bf16e8be3a5e0dc0afb7b
|
|
| BLAKE2b-256 |
da4c705cac50bff304b8dd80bf75a6dee28c1e3e273435dea57be9a7dd416e9d
|
File details
Details for the file benchspan-0.3.0-py3-none-any.whl.
File metadata
- Download URL: benchspan-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a76a3eb320203e0b6ece3a40deb715730327ca2c3bcd05d53620602467d088a
|
|
| MD5 |
0c6f6769fdefd4f44626f2bcc1b1605c
|
|
| BLAKE2b-256 |
62a01434651940cd340d95682237fdff431d833e0b4bb301485c8a12d7c16277
|