langchain-enterprise-rbac
Implement role-based access control for LangChain applications with multi-tenant isolation, model access control, and usage quotas. Trigger: "langchain RBAC", "langchain permissions", "langchain access control", "langchain multi-tenant", "enterprise LLM auth".
Best use case
langchain-enterprise-rbac is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Implement role-based access control for LangChain applications with multi-tenant isolation, model access control, and usage quotas. Trigger: "langchain RBAC", "langchain permissions", "langchain access control", "langchain multi-tenant", "enterprise LLM auth".
Teams using langchain-enterprise-rbac should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/langchain-enterprise-rbac/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How langchain-enterprise-rbac Compares
| Feature / Agent | langchain-enterprise-rbac | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Implement role-based access control for LangChain applications with multi-tenant isolation, model access control, and usage quotas. Trigger: "langchain RBAC", "langchain permissions", "langchain access control", "langchain multi-tenant", "enterprise LLM auth".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
SKILL.md Source
# LangChain Enterprise RBAC
## Overview
Role-based access control for multi-tenant LangChain applications: permission models, model access gating, tenant-scoped vector stores, usage quotas, and FastAPI middleware integration.
## Permission Model
```typescript
// permissions.ts
enum Permission {
CHAIN_INVOKE = "chain:invoke",
CHAIN_STREAM = "chain:stream",
MODEL_GPT4O = "model:gpt-4o",
MODEL_GPT4O_MINI = "model:gpt-4o-mini",
MODEL_CLAUDE = "model:claude-sonnet",
TOOLS_EXECUTE = "tools:execute",
ADMIN_CONFIG = "admin:config",
ADMIN_USERS = "admin:users",
}
interface Role {
name: string;
permissions: Permission[];
}
const ROLES: Record<string, Role> = {
viewer: {
name: "viewer",
permissions: [Permission.CHAIN_INVOKE, Permission.MODEL_GPT4O_MINI],
},
user: {
name: "user",
permissions: [
Permission.CHAIN_INVOKE,
Permission.CHAIN_STREAM,
Permission.MODEL_GPT4O_MINI,
Permission.TOOLS_EXECUTE,
],
},
power_user: {
name: "power_user",
permissions: [
Permission.CHAIN_INVOKE,
Permission.CHAIN_STREAM,
Permission.MODEL_GPT4O_MINI,
Permission.MODEL_GPT4O,
Permission.MODEL_CLAUDE,
Permission.TOOLS_EXECUTE,
],
},
admin: {
name: "admin",
permissions: Object.values(Permission),
},
};
```
## User and Tenant Models
```typescript
interface Tenant {
id: string;
name: string;
monthlyTokenLimit: number;
tokensUsed: number;
allowedModels: string[];
}
interface User {
id: string;
tenantId: string;
role: string;
email: string;
}
function hasPermission(user: User, permission: Permission): boolean {
const role = ROLES[user.role];
if (!role) return false;
return role.permissions.includes(permission);
}
function canUseModel(user: User, tenant: Tenant, model: string): boolean {
const modelPermission = `model:${model}` as Permission;
return (
hasPermission(user, modelPermission) &&
tenant.allowedModels.includes(model)
);
}
```
## Middleware: Permission Enforcement
```typescript
// Express middleware
import { Request, Response, NextFunction } from "express";
function requirePermission(permission: Permission) {
return (req: Request, res: Response, next: NextFunction) => {
const user = req.user as User; // set by auth middleware
if (!user) {
return res.status(401).json({ error: "Authentication required" });
}
if (!hasPermission(user, permission)) {
return res.status(403).json({
error: `Missing permission: ${permission}`,
role: user.role,
});
}
next();
};
}
// Usage
app.post("/api/chat",
requirePermission(Permission.CHAIN_INVOKE),
async (req, res) => {
const result = await chain.invoke({ input: req.body.input });
res.json({ result });
}
);
app.post("/api/chat/stream",
requirePermission(Permission.CHAIN_STREAM),
async (req, res) => {
// streaming endpoint...
}
);
```
## Model Access Control
```typescript
import { ChatOpenAI } from "@langchain/openai";
import { ChatAnthropic } from "@langchain/anthropic";
class ModelGateway {
private models: Record<string, any> = {};
constructor() {
this.models["gpt-4o-mini"] = new ChatOpenAI({ model: "gpt-4o-mini" });
this.models["gpt-4o"] = new ChatOpenAI({ model: "gpt-4o" });
this.models["claude-sonnet"] = new ChatAnthropic({ model: "claude-sonnet-4-20250514" });
}
getModel(modelName: string, user: User, tenant: Tenant) {
if (!canUseModel(user, tenant, modelName)) {
throw new Error(
`User ${user.email} (role: ${user.role}) cannot access model: ${modelName}`
);
}
if (tenant.tokensUsed >= tenant.monthlyTokenLimit) {
throw new Error(
`Tenant ${tenant.name} exceeded monthly token limit (${tenant.monthlyTokenLimit})`
);
}
return this.models[modelName];
}
}
```
## Tenant-Scoped Vector Store
```typescript
// Isolate each tenant's documents in the vector store
import { PineconeStore } from "@langchain/pinecone";
class TenantScopedRetriever {
constructor(
private vectorStore: PineconeStore,
private tenantId: string,
) {}
async retrieve(query: string, k = 4) {
// Filter by tenant ID — prevents cross-tenant data leakage
return this.vectorStore.similaritySearch(query, k, {
tenantId: { $eq: this.tenantId },
});
}
asRetriever(k = 4) {
return this.vectorStore.asRetriever({
k,
filter: { tenantId: { $eq: this.tenantId } },
});
}
}
// When ingesting documents, always tag with tenant ID
async function ingestForTenant(tenantId: string, docs: any[]) {
const tagged = docs.map((doc) => ({
...doc,
metadata: { ...doc.metadata, tenantId },
}));
await vectorStore.addDocuments(tagged);
}
```
## Usage Quota Tracking
```typescript
class UsageQuotaManager {
private usage = new Map<string, number>();
async trackUsage(tenantId: string, tokens: number) {
const current = this.usage.get(tenantId) ?? 0;
this.usage.set(tenantId, current + tokens);
}
async checkQuota(tenant: Tenant): Promise<boolean> {
const used = this.usage.get(tenant.id) ?? 0;
return used < tenant.monthlyTokenLimit;
}
async getUsageReport(tenantId: string) {
return {
tenantId,
tokensUsed: this.usage.get(tenantId) ?? 0,
period: new Date().toISOString().slice(0, 7), // YYYY-MM
};
}
}
// Integrate with callback
class QuotaCallback extends BaseCallbackHandler {
name = "QuotaCallback";
constructor(
private quotaManager: UsageQuotaManager,
private tenantId: string,
) { super(); }
async handleLLMEnd(output: any) {
const tokens = output.llmOutput?.tokenUsage?.totalTokens ?? 0;
await this.quotaManager.trackUsage(this.tenantId, tokens);
}
}
```
## Python FastAPI Equivalent
```python
from fastapi import Depends, HTTPException
async def get_current_user(token: str = Depends(oauth2_scheme)):
user = decode_jwt(token)
if not user:
raise HTTPException(status_code=401)
return user
def require_permission(permission: str):
async def checker(user = Depends(get_current_user)):
if permission not in ROLES[user.role]["permissions"]:
raise HTTPException(status_code=403, detail=f"Missing: {permission}")
return user
return checker
@app.post("/api/chat")
async def chat(input: dict, user = Depends(require_permission("chain:invoke"))):
return await chain.ainvoke({"input": input["text"]})
```
## Error Handling
| Issue | Cause | Fix |
|-------|-------|-----|
| 401 Unauthorized | Missing or invalid token | Check auth middleware, token format |
| 403 Forbidden | Insufficient permissions | Upgrade user role or add permission |
| Tenant data leak | Missing filter on vector store | Always filter by `tenantId` |
| Quota exceeded | High usage | Increase tenant limit or optimize |
## Resources
- [RBAC Best Practices (Auth0)](https://auth0.com/docs/manage-users/access-control/rbac)
- [Multi-Tenant Architecture](https://learn.microsoft.com/en-us/azure/architecture/guide/multitenant/)
- [OAuth 2.0 Scopes](https://oauth.net/2/scope/)
## Next Steps
Use `langchain-data-handling` for tenant-scoped RAG pipelines.Related Skills
windsurf-enterprise-rbac
Configure Windsurf enterprise SSO, RBAC, and organization-level controls. Use when implementing SSO/SAML, configuring role-based seat management, or setting up organization-wide Windsurf policies. Trigger with phrases like "windsurf SSO", "windsurf RBAC", "windsurf enterprise", "windsurf admin", "windsurf SAML", "windsurf team management".
webflow-enterprise-rbac
Configure Webflow enterprise access control — OAuth 2.0 app authorization, scope-based RBAC, per-site token isolation, workspace member management, and audit logging for compliance. Trigger with phrases like "webflow RBAC", "webflow enterprise", "webflow roles", "webflow permissions", "webflow OAuth scopes", "webflow access control", "webflow workspace members".
vercel-enterprise-rbac
Configure Vercel enterprise RBAC, access groups, SSO integration, and audit logging. Use when implementing team access control, configuring SAML SSO, or setting up role-based permissions for Vercel projects. Trigger with phrases like "vercel SSO", "vercel RBAC", "vercel enterprise", "vercel roles", "vercel permissions", "vercel access groups".
veeva-enterprise-rbac
Veeva Vault enterprise rbac for enterprise operations. Use when implementing advanced Veeva Vault patterns. Trigger: "veeva enterprise rbac".
vastai-enterprise-rbac
Implement team access control and spending governance for Vast.ai GPU cloud. Use when managing multi-team GPU access, implementing spending controls, or setting up API key separation for different teams. Trigger with phrases like "vastai team access", "vastai RBAC", "vastai enterprise", "vastai spending controls", "vastai permissions".
twinmind-enterprise-rbac
Configure TwinMind Enterprise with on-premise deployment, custom AI models, SSO integration, and team-wide transcript sharing. Use when implementing enterprise rbac, or managing TwinMind meeting AI operations. Trigger with phrases like "twinmind enterprise rbac", "twinmind enterprise rbac".
supabase-enterprise-rbac
Implement custom role-based access control via JWT claims in Supabase: app_metadata.role, RLS policies with auth.jwt() ->> 'role', organization-scoped access, and API key scoping. Use when implementing role-based permissions, configuring organization-level access, building admin/member/viewer hierarchies, or scoping API keys per role. Trigger: "supabase RBAC", "supabase roles", "supabase permissions", "supabase JWT claims", "supabase organization access", "supabase custom roles", "supabase app_metadata".
speak-enterprise-rbac
Configure Speak for schools and organizations: SSO, teacher/student roles, class management, and usage reporting. Use when implementing enterprise rbac, or managing Speak language learning platform operations. Trigger with phrases like "speak enterprise rbac", "speak enterprise rbac".
snowflake-enterprise-rbac
Configure Snowflake enterprise RBAC with system roles, custom role hierarchies, SSO/SCIM integration, and least-privilege access patterns. Use when implementing role-based access control, configuring SSO with SAML/OIDC, or setting up organization-level governance in Snowflake. Trigger with phrases like "snowflake RBAC", "snowflake roles", "snowflake SSO", "snowflake SCIM", "snowflake permissions", "snowflake access control".
windsurf-enterprise-sso
Configure enterprise SSO integration for Windsurf. Activate when users mention "sso configuration", "single sign-on", "enterprise authentication", "saml setup", or "identity provider". Handles enterprise identity integration. Use when working with windsurf enterprise sso functionality. Trigger with phrases like "windsurf enterprise sso", "windsurf sso", "windsurf".
shopify-enterprise-rbac
Implement Shopify Plus access control patterns with staff permissions, multi-location management, and Shopify Organization features. Trigger with phrases like "shopify permissions", "shopify staff", "shopify Plus organization", "shopify roles", "shopify multi-location".
sentry-enterprise-rbac
Configure enterprise role-based access control, SSO/SAML2, and SCIM provisioning in Sentry. Use when setting up organization hierarchy, team permissions, identity provider integration, API token governance, or audit logging for compliance. Trigger: "sentry rbac", "sentry permissions", "sentry team access", "sentry sso setup", "sentry scim", "sentry audit log".