Skip to main content

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

Metadata

Release files for benchspan 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for benchspan 0.3.0
File Size Uploaded Provenance Actions
benchspan-0.3.0.tar.gz 12.7 kB Without provenance Details for benchspan-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for benchspan 0.3.0
File Interpreter ABI Platform Actions
benchspan-0.3.0-py3-none-any.whl Python 3 none any Details for benchspan-0.3.0-py3-none-any.whl

Total release size: 19.4 kB

Release files / benchspan-0.3.0.tar.gz

Download URL benchspan-0.3.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a5e8f3ba4f5a493bef80cfd262ba6be44f850b5c125a418cbd91ba217b99c5e9
BLAKE2b-256 checksum
How to use checksums
da4c705cac50bff304b8dd80bf75a6dee28c1e3e273435dea57be9a7dd416e9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release files / benchspan-0.3.0-py3-none-any.whl

Download URL benchspan-0.3.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a76a3eb320203e0b6ece3a40deb715730327ca2c3bcd05d53620602467d088a
BLAKE2b-256 checksum
How to use checksums
62a01434651940cd340d95682237fdff431d833e0b4bb301485c8a12d7c16277
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Security for benchspan 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page