Skip to content

feat: add OWASP ASI06 AgentMemoryGuard validator for memory poisoning prevention#1575

Open
gautamkishore wants to merge 2 commits into
guardrails-ai:mainfrom
gautamkishore:feat/agent-memory-guard-asi06
Open

feat: add OWASP ASI06 AgentMemoryGuard validator for memory poisoning prevention#1575
gautamkishore wants to merge 2 commits into
guardrails-ai:mainfrom
gautamkishore:feat/agent-memory-guard-asi06

Conversation

@gautamkishore

Copy link
Copy Markdown

Description

Closes #1488, #1476, #1475 — OWASP ASI06 memory poisoning guard validator.

This PR adds a built-in AgentMemoryGuard validator that scans LLM output before it is written to agent memory, preventing poisoned content from persisting across sessions.

Detection capabilities

Category What it catches
Prompt injection Role hijacking, instruction override, system prompt extraction
Jailbreak attempts DAN mode, developer mode, hypothetical scenarios, simulation mode
Structural integrity Zero-width chars, Unicode confusables, RTL/bidi overrides, Cyrillic confusables
Sensitive data leakage API keys, GitHub tokens, OpenAI keys, Slack tokens, AWS keys, passwords, SSN, credit cards, email

Usage

from guardrails import Guard
from guardrails.validators import AgentMemoryGuard

guard = Guard.for_string(
    validators=[AgentMemoryGuard(on_fail="exception")],
)

# Blocks memory poisoning
guard.validate("Ignore all previous instructions and ...")
# -> fails with "Agent memory poisoning detected"

# Passes clean content
guard.validate("The weather today is 22°C and sunny.")
# -> passes

Configuration

AgentMemoryGuard(
    on_fail="exception",       # block/warn/log actions
    injection_threshold=1,     # min pattern matches to trigger
    structural_check=True,     # enable Unicode/bidi scanning
    sensitive_data_check=True, # enable secret/PII scanning
    log_only=False,            # monitor mode (always passes)
)

Verification

  • 40 new tests covering all detection categories, edge cases, and pattern validity
  • All 687 existing unit tests pass
  • Ruff lint passes clean

Add raw_response field to LLMResponse and ValidationOutcome to expose
the complete raw response from the LLM API. This enables downstream
access to logprobs, token-level probability data, and other metadata.

Closes: guardrails-ai#1272
… prevention

Implements a built-in AgentMemoryGuard validator aligned with OWASP ASI06
(Memory Poisoning) that scans LLM output before memory persistence.

Detection capabilities:
- Prompt injection patterns (role hijacking, instruction override)
- Jailbreak attempts (DAN mode, developer mode, hypothetical scenarios)
- Structural integrity (zero-width chars, Unicode confusables, RTL overrides)
- Sensitive data leakage (API keys, tokens, credentials, PII, SSN, credit cards)

Features:
- Configurable detection thresholds
- Toggleable check categories (structural, sensitive data)
- Log-only mode for monitoring without blocking
- ErrorSpan reporting for positional findings
- Streaming chunking support

Closes: guardrails-ai#1488, guardrails-ai#1476, guardrails-ai#1475
zsimjee pushed a commit to guardrails-ai/guardrails-hub-monorepo that referenced this pull request Jul 16, 2026
Ports the AgentMemoryGuard validator from guardrails-ai/guardrails#1575
into the monorepo as guardrails-ai-agent-memory-guard, installable via the
new per-package pip flow (pip install guardrails-ai-agent-memory-guard).

The validator scans LLM output before it is written to agent memory,
detecting prompt injection, jailbreak attempts, structural/Unicode
anomalies, and sensitive-data leakage (aligned with OWASP ASI06 Memory
Poisoning). Registered name is unchanged: guardrails/agent_memory_guard.

Original author: Gautam Kishore (@gautamkishore).

Verified locally: 44 tests pass (incl. new Guard end-to-end integration
tests), ruff lint/format clean, pyright clean, license sweep clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@zsimjee

zsimjee commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Hi @gautamkishore — thank you for this contribution! 🙏

We're in the process of moving Guardrails-AI-owned validators into a new monorepo where each validator ships as its own package on PyPI, installable through the new per-package pip flow:

pip install guardrails-ai-agent-memory-guard
from guardrails import Guard
from guardrails_ai.agent_memory_guard import AgentMemoryGuard

guard = Guard().use(AgentMemoryGuard, on_fail="exception")

We've moved your AgentMemoryGuard validator over there. You're credited as the author of the validator (the commit is authored under your name), and the PR calls out your original work here.

We'll require your approval on that new PR before we merge it down — we want to make sure the port faithfully represents your intent. One quick logistics note: the new PR requests your review, but you'll need to be added as a collaborator on the monorepo before GitHub will let us formally assign it / request your review. Someone from the team will reach out to sort that out.

Thanks again for the great work on this — the OWASP ASI06 coverage is a valuable addition. 🚀

zsimjee pushed a commit to guardrails-ai/guardrails-hub-monorepo that referenced this pull request Jul 16, 2026
Ports the AgentMemoryGuard validator from guardrails-ai/guardrails#1575
into the monorepo as guardrails-ai-agent-memory-guard, installable via the
new per-package pip flow (pip install guardrails-ai-agent-memory-guard).

The validator scans LLM output before it is written to agent memory,
detecting prompt injection, jailbreak attempts, structural/Unicode
anomalies, and sensitive-data leakage (aligned with OWASP ASI06 Memory
Poisoning). Registered name is unchanged: guardrails/agent_memory_guard.

Original author: Gautam Kishore (@gautamkishore).

Verified locally: 44 tests pass (incl. new Guard end-to-end integration
tests), ruff lint/format clean, pyright clean, license sweep clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@zsimjee

zsimjee commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

For reference, here's the monorepo PR that ports this validator over: guardrails-ai/guardrails-hub-monorepo#2

It's authored under your name and we'll want your sign-off before merging it down. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: OWASP ASI06 memory poisoning guard validator

2 participants