Documentation Index
Fetch the complete documentation index at: https://docs.benchspan.com/llms.txt
Use this file to discover all available pages before exploring further.
- Python 3.9+
- One runtime dependency:
httpx - Optional extra:
benchspan[langchain](only if you’re using LangChain / CrewAI)
BenchGuard
Constructor arguments
Bearer API key from Dashboard → API Keys. Format:
ag_live_....Optional label to tag every scan from this instance. Useful for filtering per-agent traffic in the dashboard.
In block mode, callbacks/hooks raise
InjectionDetectedError on detection (synchronous scan; adds typical sub-100ms scan latency). In warn mode, the scan runs in a daemon thread and the LLM call proceeds with zero added latency; detections land in your dashboard asynchronously. See Modes.Override the API host. Used for self-hosted deployments.
Methods
guard.scan(input, role="user", source=None) → ScanResult
Scan a single string synchronously. Returns the verdict; does not raise on injection. Use framework integrations or wrap for auto-raise behavior.
guard.scan_async(input, role="user", source=None) → ScanResult
Async variant of scan. Use inside async def functions.
@guard.wrap
Decorator for functions that call the LLM directly (raw OpenAI / Anthropic SDK, etc.). Scans the messages argument before the function runs.
@guard.wrap_async
Async variant of @guard.wrap. For async def functions.
LangChain / CrewAI callback
BenchGuard implements BaseCallbackHandler directly. Pass it where LangChain accepts callbacks:
guard.as_agent_hooks()
Returns an AgentHooksBase subclass (OpenAI Agents SDK) with on_tool_end wired up. See OpenAI Agents integration.
guard.as_adk_callback()
Returns a before_model_callback for Google ADK. See Google ADK integration.
Types
ScanResult
InjectionDetectedError
@guard.wrap, @guard.wrap_async, and all framework integrations when verdict == "block".
Logging
The SDK logs to thebenchspan logger. Attach a handler to see warn detections and debug output:
Thread / async safety
EachBenchGuard instance maintains a dedup cache of scanned message hashes, so don’t share an instance across unrelated agent runs if you need each run to get a fresh cache. A new instance is cheap; it’s just a config bag around httpx.