Agent skill
rag-cag-security
Security patterns for RAG and CAG systems with multi-tenant isolation. Use when building retrieval-augmented or cache-augmented generation systems that require tenant isolation, access control, and secure data handling.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/rag-cag-security
SKILL.md
RAG/CAG Security Skill
This skill provides security patterns for RAG and CAG systems.
Multi-Tenant Architecture
Tenant Isolation Strategies
- Namespace Isolation - Separate vector namespaces per tenant
- Metadata Filtering - Filter by tenant_id at query time
- Separate Collections - Isolated collections per tenant
# Metadata filtering approach
results = vector_store.similarity_search(
query,
filter={"tenant_id": current_user.tenant_id}
)
Access Control
Document-Level Permissions
@dataclass
class Document:
id: str
content: str
tenant_id: str
access_groups: list[str]
classification: str # public, internal, confidential
def can_access(user: User, doc: Document) -> bool:
return (
user.tenant_id == doc.tenant_id
and any(g in doc.access_groups for g in user.groups)
and user.clearance >= doc.classification
)
Prompt Injection Prevention
def sanitize_retrieved_context(chunks: list[str]) -> str:
"""Sanitize retrieved chunks before including in prompt."""
sanitized = []
for chunk in chunks:
# Remove potential instruction patterns
cleaned = remove_instruction_patterns(chunk)
# Escape special characters
escaped = escape_prompt_chars(cleaned)
sanitized.append(escaped)
return "\n".join(sanitized)
Data Classification
| Level | Description | Handling |
|---|---|---|
| Public | Open information | No restrictions |
| Internal | Company-only | Tenant isolation |
| Confidential | Sensitive | Encryption + audit |
| Restricted | Highly sensitive | Need-to-know basis |
Security Checklist
- Tenant isolation implemented
- Document-level access control
- Retrieved content sanitized
- Audit logging enabled
- Data encryption at rest
- Secure API authentication
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?