agentsecure
Python SDK for AgentSecure — drop-in LLM DLP proxy.
Every prompt routed through AgentSecure is scanned for PII before it reaches the model. SSNs, credit cards, and medical records are blocked. Emails, phone numbers, and names are redacted. Everything is logged in your audit trail.
Installation
# OpenAI only
pip install agentsecure-sdk[openai]
# Anthropic only
pip install agentsecure-sdk[anthropic]
# LangChain
pip install agentsecure-sdk[langchain]
# LlamaIndex
pip install agentsecure-sdk[llamaindex]
# Everything
pip install agentsecure-sdk[all]
Quick Start
Get your API key from the AgentSecure dashboard → API Keys.
export AGENTSECURE_KEY=as_xxxxxxxxxxxx
OpenAI
import agentsecure
client = agentsecure.openai(api_key="sk-...")
# Pass agentsecure_key= directly, or set AGENTSECURE_KEY env var
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "My SSN is 123-45-6789. Is that safe?"}],
)
print(response.choices[0].message.content)
# → blocked before reaching OpenAI (400 with matched pattern types)
The returned client is a plain openai.OpenAI instance — all methods, streaming, and async work exactly as documented by OpenAI.
Anthropic
import agentsecure
client = agentsecure.anthropic(api_key="sk-ant-...")
message = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
messages=[{"role": "user", "content": "Call John at 555-867-5309."}],
)
print(message.content[0].text)
# → phone number redacted; Claude sees [REDACTED]
Async
import agentsecure
aclient = agentsecure.async_openai(api_key="sk-...")
aclient_ant = agentsecure.async_anthropic(api_key="sk-ant-...")
Other providers (Groq, Mistral, Together AI, xAI, Perplexity…)
All OpenAI-compatible providers route through the OpenAI client:
import agentsecure
groq = agentsecure.client("groq", api_key="gsk_...")
response = groq.chat.completions.create(
model="llama-3.1-70b-versatile",
messages=[{"role": "user", "content": "Hello"}],
)
Supported provider names: openai, anthropic, groq, mistral, gemini,
perplexity, together, xai, cohere, huggingface.
LangChain
from agentsecure.langchain import AgentSecureChatOpenAI, AgentSecureChatAnthropic
llm = AgentSecureChatOpenAI(model="gpt-4o", openai_api_key="sk-...")
llm = AgentSecureChatAnthropic(model="claude-opus-4-7", anthropic_api_key="sk-ant-...")
These are factory functions that return standard ChatOpenAI / ChatAnthropic instances — chains, agents, and tools work without modification.
from langchain_core.prompts import ChatPromptTemplate
from agentsecure.langchain import AgentSecureChatOpenAI
chain = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant."),
("human", "{question}"),
]) | AgentSecureChatOpenAI(model="gpt-4o-mini")
result = chain.invoke({"question": "Summarise quantum computing in one sentence."})
LlamaIndex
from agentsecure.llamaindex import AgentSecureOpenAI
llm = AgentSecureOpenAI(model="gpt-4o", api_key="sk-...")
What gets detected
| Pattern | Action |
|---|---|
| SSN, passport, driver's license, bank account, credit card | Block — 400, request never reaches the LLM |
| Medical record numbers, NPI | Block |
| Email, phone, IP address, date of birth | Redact — replaced with [REDACTED] |
| Person names, organisation names (NER) | Redact — on-device BERT model |
Blocked requests raise an openai.BadRequestError (status 400) with the matched pattern types in the response body. Redacted requests return normally — the model sees the cleaned prompt.
Session tracking (Features 1 & 2)
Pass session_id to enable synthetic entity substitution and session-level accumulation detection:
import agentsecure
client = agentsecure.openai(
api_key="sk-...",
session_id="conv-abc123", # stable per conversation
user_id="user@acme.com", # optional: per-user attribution in audit log
)
With session_id set, the proxy replaces real names/orgs/locations with consistent synthetic equivalents before forwarding to the LLM, and reverses the substitution in the response. The model never sees real entities; the audit log and your app always do.
Configuration
| Parameter | Env var | Description |
|---|---|---|
agentsecure_key= |
AGENTSECURE_KEY |
Your AgentSecure API key (as_...) |
session_id= |
— | Conversation ID — enables Features 1 & 2 |
user_id= |
— | End-user identifier for audit attribution |
base_url= |
— | Override proxy URL (for self-hosted deployments) |
All other keyword arguments are passed through to the underlying client unchanged.
Dashboard
View blocked requests, redacted patterns, and full audit logs at agentsecure.vercel.app.
Metadata
Release files for agentsecure-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| agentsecure_sdk-0.1.0.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentsecure_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.5 kB
Release files / agentsecure_sdk-0.1.0.tar.gz
| Download URL | agentsecure_sdk-0.1.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d81d77837d5074c78c4b7074018b16474d8fecbef37ea4b2d20f897b7798447
|
|
BLAKE2b-256 checksum How to use checksums |
293ac5769f2d169cd224cf588b898e028eb50cfdcea0d06d3c6ddb4ae7973cd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency logRelease files / agentsecure_sdk-0.1.0-py3-none-any.whl
| Download URL | agentsecure_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd57b47780d7b1c991d7602653acba78e699f8d629ed4b15a2471ebad71c3cda
|
|
BLAKE2b-256 checksum How to use checksums |
cf32e0cf61947bd9487a9a10f6209b3b5bc1a44ed08ac4257c1bb6f1b8434b5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency log