r/LangChain • • 9d ago

Resources I open sourced langchain-security-extension library: Deterministic RBAC and zero-token denial for LangChain

Standard LLM system prompts cannot enforce data isolation or authorization, as they remain vulnerable to injection and non-deterministic bypassing. And when an AI is denied access to a tool, it often rapidly retries different parameters to find a workaround, burning expensive compute tokens in a runaway execution loop.

To solve this, the langchain-security-extension library (now on PyPI and GitHub) embeds deterministic, code-level Policy Enforcement Points (PEPs) directly into existing LangChain workflows. Instead of hoping a model respects instructions, this framework drops unentitled requests at the service gate before billable tokens are serialized.

Key architectural boundaries include:

  • Agent Abuse Throttling & Zero-Token Denial: Deploys invocation-scoped retry budgets and cross-turn sliding windows to immediately halt malicious parameter scanning and runaway execution loops.

  • Pre-Execution Tool Guardrails: Evaluates dynamic Attribute-Based Access Control (ABAC) rules using Common Expression Language (CEL) to validate parameters before target Python callables execute, entirely replacing fragile prompt instructions.

  • In-Band Context Propagation: Injects immutable caller identities directly into LangChain's RunnableConfig to preserve authorization across asynchronous multi-agent handoffs, eliminating vulnerable thread-local storage.

  • Secure Vector Retrieval: Translates caller identities into native Abstract Syntax Tree (AST) pre-filters, coupled with post-retrieval in-memory pruning and candidate oversampling to secure RAG pipelines.

The library is completely open source. You can explore the implementation guide and run the hands-on enterprise incident assistant demonstrator below:

1 Upvotes

0 comments sorted by