Proposal: Encrypted Memory Modules for LangChain (Redis + MongoDB)

Hi everyone, I’m Hemant Kumar from India.

While building CuraDocs, an AI healthcare platform, I encountered a major limitation in LangChain’s memory system:

Problem

All existing LangChain memory backends—Redis, MongoDB, Postgres—store chat history in plaintext.

For teams handling medical data, financial conversations, enterprise workflows, or any form of PII, this makes the default memory adapters unsafe for production use.

Because of this, many teams cannot adopt LangChain memory directly.

Proposal

Introduce encrypted memory modules for LangChain, providing secure, drop-in alternatives to the existing backends.

These modules are already fully implemented, tested, documented, and available as open-source packages:

1. Encrypted Redis Memory (langchain-encrypted-redis-memory)

A secure replacement for RedisChatMessageHistory that encrypts every stored message using AES-128 (Fernet).

:check_mark: Same API — no integration changes
:check_mark: Transparent encryption/decryption
:check_mark: Ideal for short-term memory in RAG and agent pipelines

PyPI:
https://pypi.org/project/langchain-encrypted-redis-memory/

GitHub:
https://github.com/HATAKEkakshi/langchain-encrypted-redis-memory.git

2. Encrypted MongoDB Memory (langchain-encrypted-mongo-memory)

A persistent, encrypted alternative to MongoDBChatMessageHistory, suited for long-term chat storage.

:check_mark: AES-128 encrypted message storage
:check_mark: Protects message content + session identifiers
:check_mark: Designed for production copilots in healthcare, finance, and enterprise

PyPI:
https://pypi.org/project/langchain-encrypted-mongo-memory/

GitHub:
https://github.com/HATAKEkakshi/langchain-encrypted-mongo-memory.git

Integration Guide

A full Jupyter notebook demonstrating encrypted memory with LangChain:

:link:
https://github.com/HATAKEkakshi/integration-guide/blob/main/examples/langchain-encrypted-memory-example.ipynb

The guide includes:

  • Using encrypted Redis & MongoDB memory

  • Retrieving decrypted messages

  • Best practices (hashed session IDs)

  • Comparison with plaintext memory

Category Requested

New Proposal → Memory → Security → Encrypted Chat Memory History

Happy to collaborate and refine structure, naming, or implementation details based on maintainer feedback.

Thanks for reviewing this proposal—looking forward to your thoughts!

Hemant Kumar

Hi @HATAKEkakshi ,

We offer encryption as part of langgraph checkpointing. Documentation is available here: Persistence - Docs by LangChain

We recommend that all applications use langgraph checkpointing for memory (not ChatMessageHistory, which is a very old implementation of memory at this point).

All the best,

Eugene

Great thread @HATAKEkakshi — encryption at rest is one half of the memory security story, but there’s a complementary problem: integrity validation at write time.

Even with encrypted backends, if an attacker injects malicious content into agent memory (via prompt injection, tool-call poisoning, or context manipulation), the encrypted store faithfully persists the poisoned data. Encryption protects confidentiality but not integrity.

This is exactly what Agent Memory Guard addresses — it’s an OWASP project that provides runtime integrity scanning on every memory write:

  • SHA-256 cryptographic baselines detect unauthorized modifications
  • Prompt injection detection catches injected instructions before they’re persisted
  • Sensitive data leakage detection prevents PII from being written to memory
  • Policy enforcement via declarative YAML rules

It ships with GuardedChatMessageHistory as a drop-in for LangChain:

from agent_memory_guard.integrations.langchain import GuardedChatMessageHistory

history = GuardedChatMessageHistory(
    session_id="user-123",
    policy="strict"
)

The ideal production stack would be: Agent Memory Guard (integrity) + your encrypted backends (confidentiality) — defense in depth.

pip install agent-memory-guard

@eyurtsev — for teams using LangGraph checkpointing, AMG can wrap the checkpointer as a pre-write validation hook. Would love to discuss integration patterns.