Metadata-Version: 2.3
Name: langchain-permit
Version: 0.1.0
Summary: Access control tools and retrievers for LangChain.
License: MIT
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: chromadb (>=0.6.3,<0.7.0)
Requires-Dist: jwcrypto (>=1.5.6,<2.0.0)
Requires-Dist: langchain (>=0.3.18,<0.4.0)
Requires-Dist: langchain-community (>=0.3.17,<0.4.0)
Requires-Dist: langchain-core (>=0.3.15,<0.4.0)
Requires-Dist: langchain-openai (>=0.3.5,<0.4.0)
Requires-Dist: langchain-tests (>=0.3.11,<0.4.0)
Requires-Dist: libmagic (>=1.0,<2.0)
Requires-Dist: openai (>=1.63.0,<2.0.0)
Requires-Dist: permit (>=2.7.1,<3.0.0)
Requires-Dist: pydantic (>=2.10.6,<3.0.0)
Requires-Dist: pyjwt (>=2.10.1,<3.0.0)
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
Requires-Dist: tiktoken (>=0.9.0,<0.10.0)
Requires-Dist: unstructured (>=0.16.20,<0.17.0)
Project-URL: Repository, https://github.com/permitio/langchain-permit
Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22permit%3D%3D0%22&expanded=true
Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/partners/permit
Description-Content-Type: text/markdown

# LangChain Permit Integration

Fine-grained authorization for LangChain using Permit.io: Seamlessly control document access, API interactions, and AI responses with robust, role-based permission management across your AI applications.

## Overview

This package provides a comprehensive authorization layer for LangChain applications, leveraging Permit.io's advanced permission management system. It enables developers to implement granular access controls across different stages of AI-powered workflows.

## Key Features

- 🔒 JWT Token Validation
- 🛡️ Role-Based Access Control
- 📄 Document Retrieval Filtering
- 🤖 AI Action Authorization

## Installation

```bash
pip install langchain-permit
```

## Configuration

Set up your Permit.io credentials:

```bash
export PERMIT_API_KEY='your-permit-api-key'
export JWT_SECRET_KEY='your-jwt-secret-key'  # Optional
```

## Authorization Perimeters

The integration covers four critical authorization domains:

1. **Prompt Protection**

   - Validate user permissions before processing AI prompts
   - Prevent unauthorized query generation

2. **RAG Data Filter**

   - Filter document retrieval based on user roles
   - Ensure users access only permitted documents

3. **AI Action Authorization**

   - Control API endpoint access
   - Implement approval workflows for sensitive actions

4. **Response Protection**
   - Filter and sanitize AI-generated responses
   - Prevent information leakage

## Usage Examples

### Permission Checking

```python
from langchain_permit import LangchainPermitTool

# Initialize permission tool
permit_tool = LangchainPermitTool(
    user_id='user123',
    jwt_token='user_jwt_token'
)

# Check permission
is_permitted = permit_tool.run(
    action='read',
    resource='financial_documents'
)
```

### RAG with Permission Filtering

```python
from langchain_permit import LangchainPermitRetriever

# Initialize retriever with user context
retriever = LangchainPermitRetriever(
    user_id='finance_user',
    jwt_token='finance_jwt_token'
)

# Retrieves only documents user is authorized to access
documents = retriever.invoke("Q1 financial summary")
```

## Advanced Configuration

### Custom PDP URL

```python
permit_tool = LangchainPermitTool(
    api_key='your-api-key',
    pdp_url='https://custom-pdp.permit.io'
)
```

## Requirements

- Python 3.8+
- LangChain
- Permit.io Account

## Contributing

Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details.

