Skip to main content

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

apexguard-0.1.5.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

apexguard-0.1.5-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file apexguard-0.1.5.tar.gz.

File metadata

  • Download URL: apexguard-0.1.5.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

Hashes for apexguard-0.1.5.tar.gz
Algorithm Hash digest
SHA256 8e32476a56a471a0319095d5337defde2300d9a590da615b6fbcdd86a482e5f0
MD5 bca16235d9ea9e1118c40b79badfc9a0
BLAKE2b-256 03a1e711c7112e4ba8317f9840c09a6f480fa45584bd56b1eab175951c47d6a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for apexguard-0.1.5.tar.gz:

Publisher: release.yml on kshkrao3/agentshield

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apexguard-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: apexguard-0.1.5-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

Hashes for apexguard-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2c203d19eefb8dbe659531d9d2446cd9ffd96e93207932c261671daea32184b4
MD5 efa18be181876018836f121ae19d4125
BLAKE2b-256 5132273441a3bf07dfc0d5663babb3589f845da66967f527284f0498549f2db4

See more details on using hashes here.

Provenance

The following attestation bundles were made for apexguard-0.1.5-py3-none-any.whl:

Publisher: release.yml on kshkrao3/agentshield

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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