Runtime security middleware for LLM agents — prompt injection, tool misuse, and memory poisoning defense
Project description
agentshield
Runtime security middleware for LLM agents. Drop it into your existing agent framework — no refactor required.
Defends against:
- Prompt injection (user input hijacking system instructions)
- Tool misuse & privilege escalation (agents calling tools outside intended scope)
- Memory poisoning (persistent agent memory corrupted across sessions)
- RAG context injection (poisoned document chunks injecting instructions)
Install
pip install apexguard
# or
npm install @apexguard/sdk
Python — 30-second quickstart
from apexguard import Shield, Policy
shield = Shield(
policy=Policy(
tool_allowlist=["calculator", "web_search"],
memory_ttl=3600,
injection_sensitivity="medium",
on_violation="block",
)
)
# Wrap your existing LangChain agent
secured_agent = shield.wrap(your_langchain_agent)
result = secured_agent.invoke({"input": user_query})
LangChain tool integration
from apexguard.adapters.langchain import shield_tools
secured_tools = shield_tools(your_tools, shield)
agent = create_react_agent(llm, secured_tools, prompt)
Custom violation handler
shield.on_violation(lambda e: send_to_slack(e))
TypeScript — 30-second quickstart
import { Shield } from '@apexguard/sdk';
const s = new Shield({
policy: {
toolAllowlist: ['calculator', 'webSearch'],
memoryTTL: 3600,
injectionSensitivity: 'medium',
onViolation: 'block',
},
});
const securedAgent = s.wrap(yourAgent);
Vercel AI SDK tools
import { shieldTools } from '@apexguard/sdk/adapters/vercel-ai';
const result = await generateText({
model: openai('gpt-4o'),
tools: shieldTools({ calculator, webSearch }, s),
prompt: userInput,
});
Modules
| Module | What it does |
|---|---|
PromptFirewall |
Pattern-matching injection detector — 0 external calls, <1ms |
ToolSentinel |
Allowlist/denylist + per-turn rate limiting for tool calls |
MemoryGuard |
TTL enforcement + untrusted-write quarantine for agent memory |
Policy options
| Option | Default | Description |
|---|---|---|
tool_allowlist |
None |
Whitelist of permitted tool names. None = all allowed |
tool_denylist |
[] |
Hard-blocked tool names |
memory_ttl |
3600 |
Memory entry lifetime in seconds. 0 = no expiry |
injection_sensitivity |
"medium" |
Pattern set: low / medium / high |
on_violation |
"warn" |
"warn" (log only), "block" (raise), "quarantine" (suppress) |
max_tool_calls_per_turn |
20 |
Rate limit per agent turn |
max_memory_entries |
1000 |
Cap on memory store size |
License
Apache 2.0
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apexguard-0.1.6.tar.gz.
File metadata
- Download URL: apexguard-0.1.6.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a821a3e350e5bdb55f375fabd4d38d4f76f468d1867ee3ae232c2bdb3a079bdf
|
|
| MD5 |
6b3b575936e406979f5671fa5307e9ca
|
|
| BLAKE2b-256 |
dc5858140c4a4fc43782b0c48c9f4cd50b294fcd0fded12ae7c3e3431799c7cf
|
Provenance
The following attestation bundles were made for apexguard-0.1.6.tar.gz:
Publisher:
release.yml on kshkrao3/agentshield
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
apexguard-0.1.6.tar.gz -
Subject digest:
a821a3e350e5bdb55f375fabd4d38d4f76f468d1867ee3ae232c2bdb3a079bdf - Sigstore transparency entry: 1398985491
- Sigstore integration time:
-
Permalink:
kshkrao3/agentshield@f7583dcee8e169f6b367383034115ce7df0e504e -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/kshkrao3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7583dcee8e169f6b367383034115ce7df0e504e -
Trigger Event:
push
-
Statement type:
File details
Details for the file apexguard-0.1.6-py3-none-any.whl.
File metadata
- Download URL: apexguard-0.1.6-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
105922844f7706c6fffcbb14a99a89495022f5791035e622ca947afd8ac798ac
|
|
| MD5 |
ff95cae23bb6ef124411f320b9b3e780
|
|
| BLAKE2b-256 |
f68722150d4fe6b9b83ed0293230e7c95d6db5dab8c9eaac51b334470350d5a4
|
Provenance
The following attestation bundles were made for apexguard-0.1.6-py3-none-any.whl:
Publisher:
release.yml on kshkrao3/agentshield
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
apexguard-0.1.6-py3-none-any.whl -
Subject digest:
105922844f7706c6fffcbb14a99a89495022f5791035e622ca947afd8ac798ac - Sigstore transparency entry: 1398985498
- Sigstore integration time:
-
Permalink:
kshkrao3/agentshield@f7583dcee8e169f6b367383034115ce7df0e504e -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/kshkrao3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f7583dcee8e169f6b367383034115ce7df0e504e -
Trigger Event:
push
-
Statement type: