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.3.0.tar.gz (12.7 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.3.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

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

Hashes for benchspan-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a5e8f3ba4f5a493bef80cfd262ba6be44f850b5c125a418cbd91ba217b99c5e9
MD5 f42a9c55647bf16e8be3a5e0dc0afb7b
BLAKE2b-256 da4c705cac50bff304b8dd80bf75a6dee28c1e3e273435dea57be9a7dd416e9d

See more details on using hashes here.

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

Hashes for benchspan-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a76a3eb320203e0b6ece3a40deb715730327ca2c3bcd05d53620602467d088a
MD5 0c6f6769fdefd4f44626f2bcc1b1605c
BLAKE2b-256 62a01434651940cd340d95682237fdff431d833e0b4bb301485c8a12d7c16277

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