Add Langchain integration for RAG authorization support #407
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds comprehensive authorization support for Langchain applications, particularly focusing on RAG (Retrieval-Augmented Generation) systems. As AI and LLM applications become more prevalent, there's a growing need for robust access control to protect sensitive data and ensure users only access authorized resources.
What's New
LangchainEnforcer Integration
A new
LangchainEnforcer
class provides Langchain-specific authorization methods wrapped around Casbin's powerful policy engine:Key Features
🔒 Document Access Control for RAG
document:public:*
,document:analytics:*
)🛠️ Tool Usage Authorization
🤖 Agent Execution Control
🏢 Multi-Tenant Support
Authorization Models
Two pre-configured models are included:
Basic RAG Model - Single-tenant authorization with RBAC and pattern matching:
Multi-Tenant Model - Domain-aware authorization:
Example Policies
Use Cases
This integration is ideal for:
Testing
Documentation
Complete documentation included:
examples/langchain/README.md
Files Changed
New:
casbin/integrations/langchain.py
- Core integration modulecasbin/integrations/__init__.py
- Integration exportsexamples/langchain_rag_model.conf
- Basic RAG authorization modelexamples/langchain_rag_policy.csv
- Example policiesexamples/langchain_with_domains_model.conf
- Multi-tenant modelexamples/langchain_with_domains_policy.csv
- Multi-tenant policiesexamples/langchain/basic_rag_example.py
- Basic usage exampleexamples/langchain/multi_tenant_example.py
- Multi-tenant exampleexamples/langchain/README.md
- Integration documentationtests/test_langchain_integration.py
- Test suiteModified:
casbin/__init__.py
- Export integrations moduleREADME.md
- Add Langchain integration sectionBenefits
Closes #XXX
Original prompt
Fixes #401
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.