Skip to main content

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. Raises InjectionDetectedError if 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

  1. Framework hook fires before each LLM call
  2. SDK scans user and tool messages via the BenchSpan API
  3. system and assistant messages are skipped (trusted)
  4. Already-scanned messages are deduplicated across multi-turn conversations
  5. In block mode, InjectionDetectedError is raised if injection detected
  6. 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.2.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

benchspan-0.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file benchspan-0.2.0.tar.gz.

File metadata

  • Download URL: benchspan-0.2.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for benchspan-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b254badb5f4ab99cd65c93194768038b4ace6682a693c081f15b7bbe56d89d78
MD5 06441a9e6c154b77d82d73c39be9d2a1
BLAKE2b-256 501aa9e0b14c693a326b8833cfb4e414a9e1f6c2fbaf4f1be9f4cc184446dd31

See more details on using hashes here.

File details

Details for the file benchspan-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: benchspan-0.2.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

Hashes for benchspan-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 816febc1c4174fd2afdee03baafa98562611d094c6ab8e0ef6b94a2f2f451799
MD5 e59e650b28a719c250f73778cbcb5b11
BLAKE2b-256 38f6c8435775812bafbc006e7f6aa199af6746c0c3928494628260a587dbb475

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