Skip to main content

Runtime security SDK for AI agents — guard tool calls in 1 line

Project description

Clampd Python SDK

Runtime security for AI agents. Guard every tool call — OpenAI, Anthropic, LangChain, Google ADK — in 1 line. Prompt and response scanning enabled by default.

Installation

pip install clampd

With framework extras:

pip install clampd[langchain]    # LangChain callback handler
pip install clampd[mcp]          # MCP server support
pip install clampd[all]          # Everything

Quick Start

import clampd
from openai import OpenAI

# Configure once at startup
clampd.init(
    agent_id="my-agent",
    secret="ags_...",              # from dashboard → Agent → Secret
    gateway_url="http://localhost:8080",
    api_key="ag_live_...",
)

# Wrap your OpenAI client — done
client = clampd.openai(OpenAI())

# Use it exactly like before. Clampd intercepts every tool call.
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Look up active users"}],
    tools=[...],
)
# Dangerous tool calls → blocked before execution
# Safe tool calls → proceed normally
# Prompts scanned before LLM, responses scanned after

What's New in 0.4.0

  • scan_input and scan_output now default to True — prompts are scanned before the LLM call, responses are scanned after. Set scan_input=False to opt out.
  • 50 detection rules across 20 languages
  • 7 compliance frameworks (HIPAA, GDPR, PCI-DSS, CCPA, SOC 2, EU AI Act, NIST AI RMF)

Configuration

Three ways to configure (pick one):

# Option 1: Environment variables
# export CLAMPD_GATEWAY_URL=http://localhost:8080
# export CLAMPD_API_KEY=ag_live_...
# export CLAMPD_AGENT_ID=my-agent
# export JWT_SECRET=ags_...

# Option 2: Global init (recommended)
clampd.init(agent_id="my-agent", secret="ags_...", gateway_url="...", api_key="...")

# Option 3: Inline per-call
@clampd.guard("db.query", agent_id="my-agent", secret="ags_...", gateway_url="...", api_key="...")
def query(sql): ...

Anthropic / Claude

import clampd
from anthropic import Anthropic

clampd.init(agent_id="my-agent", secret="ags_...")
client = clampd.anthropic(Anthropic())

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "..."}],
    tools=[...],
)

LangChain

import clampd

handler = clampd.langchain(agent_id="my-agent", secret="ags_...")

result = executor.invoke(
    {"input": "Look up active users"},
    config={"callbacks": [handler]},
)

Google ADK

import clampd
from google.adk import Agent

agent = Agent(
    tools=[...],
    before_tool_callback=clampd.adk(agent_id="my-agent", secret="ags_..."),
)

Direct Guard (any function)

import clampd

clampd.init(agent_id="my-agent", secret="ags_...")

@clampd.guard("database.query")
def run_query(sql: str):
    return db.execute(sql)

# With response checking (opt-in)
@clampd.guard("file_read", check_response=True)
def read_file(path: str):
    return open(path).read()

run_query("SELECT * FROM users")     # allowed
run_query("DROP TABLE users")        # raises ClampdBlockedError

Scanning Options

# Defaults (v0.4.0+): scan_input=True, scan_output=True
client = clampd.openai(OpenAI(), agent_id="my-agent")

# Opt out of scanning
client = clampd.openai(OpenAI(),
    agent_id="my-agent",
    scan_input=False,   # skip prompt scanning
    scan_output=False,  # skip response scanning
)

Error Handling

from clampd import ClampdBlockedError

try:
    run_query("DROP TABLE users")
except ClampdBlockedError as e:
    print(f"Blocked: {e}")
    # e.risk_score, e.denial_reason, e.request_id

API Reference

Function Description
clampd.init(...) Configure global client (once at startup)
clampd.openai(client, **opts) Wrap OpenAI client (scan_input/scan_output on by default)
clampd.anthropic(client, **opts) Wrap Anthropic client (scan_input/scan_output on by default)
clampd.guard(tool_name, **opts) Decorator for any function
clampd.langchain(...) LangChain callback handler
clampd.adk(...) Google ADK before_tool_callback

Requirements

  • Python 3.10+
  • A running Clampd gateway

License

BUSL-1.1

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

clampd-0.5.0.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

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

clampd-0.5.0-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file clampd-0.5.0.tar.gz.

File metadata

  • Download URL: clampd-0.5.0.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for clampd-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e7b49998266f409d23710caaf14f572a77282e39d66b43b95acb93d9a9b816b7
MD5 6986ddb11f4cfeb9d8230ce6910c545b
BLAKE2b-256 189e8ddad091c1a571ee98ba6312ea7e4b4195e3218a1036238af752687d5876

See more details on using hashes here.

File details

Details for the file clampd-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: clampd-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for clampd-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b3e89766b9edcc9ddce0ee8b57c69511db9db9988b16e9051090d5580f10bc
MD5 17b824545a4fca4bcf01ebfca04232d9
BLAKE2b-256 6747b33a2cc597c9f79f87e5cb5703a17b95d11199ab4398572143e9d5bbfe1d

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