This article demonstrates how to secure AI agent state by implementing Client-Side Field Level Encryption (CSFLE) for LangGraph checkpoints stored in MongoDB. By extending LangGraph's serialization protocols, developers can ensure that sensitive session data remains encrypted at rest, protecting it from unauthorized database access while maintaining functionality.
Key points
LangGraph checkpoints often contain sensitive user data that requires encryption to satisfy security and compliance requirements.
The default MongoDBSaver implementation stores checkpoints as base64-encoded blobs, which are effectively plaintext to database users.
Implementing a custom CipherProtocol allows integration with MongoDB CSFLE to encrypt serialized checkpoint payloads before database persistence.
Encryption keys should be managed via external KMS providers like AWS KMS, Azure Key Vault, or GCP KMS for robust security.
Encrypted payloads cannot be used as query filters, necessitating trade-offs between data confidentiality and queryability.