Skip to main content

LangGraph-SecureAgents

Deterministic authorization for LangGraph-powered agents.

PyPI version Python versions CI Latest GitHub release MIT License

LangGraph-SecureAgents evaluates authorization in trusted application code and can enforce the decision immediately before a protected Python callable or agent tool executes. LangGraph can orchestrate the agent; an LLM cannot grant itself permissions.

Security model: Authorization is enforced at the callable and agent-tool boundaries you configure. The integrating application remains responsible for authenticating callers, constructing principals from trusted context, mapping each request to the actual resource being accessed, and retaining downstream access controls. See the threat model for the trust boundaries and deployment guidance.

What it provides

  • Deterministic policy evaluation with default-deny behavior and explicit-deny rules taking precedence over allow rules.
  • Principal- and role-based access control over application-defined actions and resources.
  • Callable protection with protect_callable, so authorization is checked immediately before execution.
  • Optional LangChain agent middleware that checks tool calls before the tool handler runs.
  • Human-approval interrupts for selected sensitive agent actions.
  • Fail-closed controls when configured audit callbacks or authorization-related checks fail.

How it fits into an application

The host application authenticates the caller and constructs a trusted Principal. The policy engine then evaluates a concrete action/resource request before a guarded operation proceeds.

Trusted application identity
           |
           v
        Principal
           |
           v
      PolicyEngine
           |
   allow / deny / approval
           |
           v
 Python callable or agent tool
           |
   execute only if authorized

The library does not authenticate users or make untrusted runtime context trustworthy. Those responsibilities stay with the application.

Installation

Requires Python 3.11 or newer.

Install the core policy engine and callable guard:

python -m pip install langgraph-secure-agents

For the optional LangChain/LangGraph agent middleware:

python -m pip install "langgraph-secure-agents[langchain-agents]"

The core policy engine does not require an LLM provider or the optional agent middleware dependencies.

Quick start: evaluate an authorization policy

This example requires no LLM or agent framework.

from langgraph_secure_agents import (
    AccessRequest,
    DecisionReason,
    Effect,
    PolicyEngine,
    PolicyRule,
    Principal,
)

policy = PolicyEngine(
    [
        PolicyRule(
            rule_id="analysts-read-reports",
            effect=Effect.ALLOW,
            roles=frozenset({"analyst"}),
            actions=frozenset({"read"}),
            resources=frozenset({"reports"}),
        )
    ]
)

request = AccessRequest(
    principal=Principal("user-123", roles=frozenset({"analyst"})),
    action="read",
    resource="reports",
)

decision = policy.evaluate(request)

assert decision.allowed
assert decision.reason is DecisionReason.EXPLICIT_ALLOW

A request with no matching allow rule is denied by default. An explicit matching deny rule overrides an allow rule. Use the public DecisionReason enum for machine-readable outcomes rather than matching free-form text.

Protect an existing Python callable

Wrap a function that accesses a protected resource. The resolver must identify the same resource that the function actually accesses.

from langgraph_secure_agents import (
    Effect,
    PolicyEngine,
    PolicyRule,
    Principal,
    protect_callable,
)

report_policy = PolicyEngine(
    [
        PolicyRule(
            rule_id="analysts-read-report-123",
            effect=Effect.ALLOW,
            roles=frozenset({"analyst"}),
            actions=frozenset({"read"}),
            resources=frozenset({"report:123"}),
        )
    ]
)


def current_principal() -> Principal:
    # Replace with trusted, request-scoped identity from your application.
    return Principal("user-123", roles=frozenset({"analyst"}))


protected_lookup = protect_callable(
    lookup_report,  # Your existing function
    policy=report_policy,
    principal_resolver=current_principal,
    action="read",
    resource_resolver=lambda report_id: f"report:{report_id}",
)

# Authorization is checked before the protected function executes.
report = protected_lookup("123")

For multi-user applications, resolve identity from authenticated request context; do not capture one user's identity in a process-wide shared tool. Resolver logic and policy configuration are security-sensitive application code.

Optional agent middleware

Install the langchain-agents extra and add the authorization middleware to a supported LangChain agent:

from langgraph_secure_agents.middleware import create_authorization_middleware

authorization_middleware = create_authorization_middleware(
    policy,
    principal_resolver=resolve_principal,
)

Pass authorization_middleware to the agent's middleware configuration. resolve_principal must construct a Principal from trusted runtime context. By default, the policy action is execute and the resource is the tool name; custom resolvers can map tool calls to domain-specific actions and resources. A denied call returns an error tool message without invoking the tool handler.

For sensitive actions, a policy can use Effect.REQUIRE_APPROVAL to pause execution for a human decision. This requires LangGraph 1.2 or newer with an active checkpointer. The host application must authenticate the reviewer, secure the resume endpoint, and enforce one-time approval consumption for side-effecting operations. An approval fingerprint alone is not proof of reviewer identity or a one-time token.

Security responsibilities

Integrators must:

  • Authenticate callers and derive principals and roles from trusted, validated server-side data.
  • Apply guards to every path that can invoke a sensitive operation.
  • Ensure each resource resolver matches the exact resource and tenant used by the protected operation.
  • Keep downstream services and data stores' own authorization controls enabled.
  • Configure and operate durable audit storage when audit persistence is required.

This library does not provide authentication, tenant isolation, prompt-injection prevention, secrets management, rate limiting, or a human-reviewer service. Read the threat model and security policy before evaluating it for your use case.

Run the example

The repository includes a model-free LangGraph workflow using mock payroll records. It needs no model API key:

python examples/policy_guarded_workflow.py

The example shows one allowed HR request and two denied requests: one for an unapproved resource and one from a caller without the required role.

Development and testing

Install the development dependencies from a source checkout:

python -m pip install -e ".[dev]"
ruff check .
ruff format --check .
mypy src
pytest --cov=langgraph_secure_agents --cov-report=term-missing --cov-fail-under=98

CI tests Python 3.11, 3.12, and 3.13, checks linting, formatting, and types, and enforces a 98% minimum line-coverage threshold. The packaging workflow also validates the wheel and source distribution and smoke-tests the installed package and optional middleware extra.

Project documentation

  • Threat model — trust boundaries, intended mitigations, and remaining application responsibilities.
  • Security policy — project status and vulnerability reporting.
  • Changelog — user-facing changes by release.
  • Releasing — maintainer information about automated releases.

License

MIT. See LICENSE.

Metadata

Release files for langgraph-secure-agents 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langgraph-secure-agents 0.1.1
File Size Uploaded Provenance
langgraph_secure_agents-0.1.1.tar.gz 33.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for langgraph-secure-agents 0.1.1
File Interpreter ABI Platform
langgraph_secure_agents-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.4 kB

Release files / langgraph_secure_agents-0.1.1.tar.gz

Download URL langgraph_secure_agents-0.1.1.tar.gz
Size 33.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4a4dfaea5ffc773a7197ec65d2da91619e7e737c7719a0de138eb762723fe581
BLAKE2b-256 checksum
How to use checksums
53d5ef74ddc9be0c129f642a14c5fffba57aea6b0432f5512b260d40657d8719
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / langgraph_secure_agents-0.1.1-py3-none-any.whl

Download URL langgraph_secure_agents-0.1.1-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e03afb10c9e5194cf64164db7895fee00f1f65f573c8cdc6d50f939c9c9f1f85
BLAKE2b-256 checksum
How to use checksums
6360c0ea1b910fb25bfacf3798b41f6f17e1e896f52d85e207c9490330ff1bb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for langgraph-secure-agents 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langgraph_secure_agents-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page