Overview
The Secure MCP Gateway provides two Python modules for protecting LangChain and LangGraph applications:- LangChain Module -
BaseCallbackHandlerfor any LangChain component - LangGraph Module -
pre_model_hookandpost_model_hookfor LangGraph agents
LangChain Integration
Use theEnkryptGuardrailsHandler to protect any LangChain component including LLMs, chains, agents, tools, and retrievers.
Installation
Configure Guardrails
Basic Usage
Supported Hooks
TheEnkryptGuardrailsHandler implements all LangChain BaseCallbackHandler methods:
Usage Examples
With Chains
With Agents
With Retrievers (RAG)
Audit-Only Mode
Disable Sensitive Tool Blocking
LangGraph Integration
For LangGraph’screate_react_agent, use pre_model_hook and post_model_hook.
Installation
Basic Usage
Convenience Functions
Tool Wrapping
Configuration
LangChain Configuration
guardrails_config.json
LangGraph Configuration
guardrails_config.json
Available Detectors
Logging
Logs are written to~/langchain/guardrails_logs/ or ~/langgraph/guardrails_logs/:
on_llm_start.jsonl/pre_model_hook.jsonl- Input validationon_llm_end.jsonl/post_model_hook.jsonl- Output validationon_tool_start.jsonl/before_tool_call.jsonl- Tool input checkscombined_audit.jsonl- All events combinedsecurity_alerts.jsonl- Security violations
View Logs
Metrics
Error Handling
Comparison
Use LangChain module for:
- Standalone LangChain components
- Chains and pipelines
- RAG applications
- Any non-LangGraph agent
- LangGraph’s
create_react_agent - LangGraph workflows
Testing
Next Steps
CrewAI Integration
Protect multi-agent CrewAI systems
Configure Policies
Create custom guardrail policies
View Metrics
Monitor guardrails performance
Audit Logs
Review security events