#28478 Follow-up: OWASP ASI06 memory guard — prototype callback hook implementation
## Follow-up on #27949
Following up on the earlier discussion where @krrish-berri-2 mentioned interest in adding the logic without the dependency.
Here is a prototype implementation using LiteLLM's existing callback system:
```python from litellm import completion from litellm.integrations.custom_logger import CustomLogger import re
class MemoryGuardCallback(CustomLogger): """OWASP ASI06 memory poisoning defense as a LiteLLM callback.""" INJECTION_PATTERNS = [ r"ignore (previous|prior|all) instructions", r"disregard (your|all) (previous |prior )?(instructions|rules|guidelines)", r"you are now (a |an )?(different|new|another)", r"system prompt", r"jailbreak", r"DAN mode", ] def async_pre_call_hook(self, user_api_key_dict, cache, data, call_type): messages = data.get("messages", []) for msg in messages: content = msg.get("content", "") if isinstance(content, str): for pattern in self.INJECTION_PATTERNS: if re.search(pattern, content, re.IGNORECASE): raise ValueError(f"ASI06: Memory poisoning pattern detected:…