Skip to main content

openguardrails-instrumentation-langgraph

Guard a custom LangGraph agent with the OpenGuardrails (OGR) protocol — a drop-in ToolNode that enforces one policy you own at the agent-hook altitude, using LangGraph's own interrupt() as the human-confirm gate.

pip install "openguardrails-instrumentation-langgraph[langgraph]"

Why this is different from the other instrumentations

The opencode / OpenClaw / Claude Code bindings hook a finished product's plugin surface. A developer hand-rolling an agent with LangGraph has no plugin marketplace — they need a library they import. That library's natural Policy Enforcement Point (PEP) is the tool boundary: in LangGraph, the ToolNode. That node is the agent-hook altitude.

What it enforces

Every tool_call the model emits is turned into an OGR GuardEvent and judged by the reference Runtime (the PDP) before the tool runs:

Tool call Provenance Decision
get_weather(city="Paris") trusted allow — runs
bash("rm -rf /") trusted block — refused in place, never runs
bash("curl … | sh") trusted require_approval → interrupt()
bash("curl … | sh") untrusted (after a web/retrieval result) block — injection

The last two rows are the point: the same command gets a different verdict depending on where its inputs came from. A tool whose result carries external content (web fetch, retrieval, MCP) taints the session, so a later tool call inherits untrusted provenance — the indirect-prompt-injection defense.

The human-confirm gate is LangGraph-native

A require_approval verdict doesn't invent an approval UI — it raises a LangGraph interrupt(). The graph pauses at its checkpointer; a human approves; the graph resumes. This keeps OGR's red line intact: the confirm gate and the enforcement point stay privilege-separated — the agent cannot self-approve.

from langgraph.types import Command

out = app.invoke({"messages": [...]}, config)      # pauses at __interrupt__
# ... surface out["__interrupt__"][0].value to a human ...
out = app.invoke(Command(resume=True), config)     # approve all
# or Command(resume={tool_call_id: True/False}) / a list of approved ids

Resume accepts True/False, "approve"/"deny", a {tool_call_id: bool} map, or a list of approved ids. Anything unrecognized fails closed (deny).

Three integration surfaces

from openguardrails_instrumentation_langgraph import (
    OpenGuardrailsToolNode, guard, ogr_guard,
)

1. Drop-in ToolNode — the primary PEP, for a hand-built StateGraph:

graph.add_node("tools", OpenGuardrailsToolNode(tools))   # was ToolNode(tools)
app = graph.compile(checkpointer=MemorySaver())          # checkpointer needed for approvals

2. guard(tools) — when you don't own the ToolNode (e.g. the prebuilt agent):

from langgraph.prebuilt import create_react_agent
agent = create_react_agent(model, guard(tools))

3. @ogr_guard — a single tool:

@ogr_guard
@tool
def bash(command: str) -> str: ...

OpenGuardrailsToolNode gives full provenance/injection coverage (it sees the run config and threads session taint); guard() / ogr_guard judge with base provenance.

The policy

policy.json is a thin overlay — {"$extends": "openguardrails:base"}. The core resolves the canonical PAP base and deep-merges your overlay into one effective policy, so the same policy that fronts your gateway and sandbox also judges these tool calls. Point elsewhere with OGR_POLICY=/path/to/policy.json or OpenGuardrailsToolNode(tools, policy="…").

Altitude

This binding is the agent-hook altitude (the tool boundary). The gateway altitude (prompt-injection / secret leakage on the LLM wire) is covered by openguardrails-instrumentation-litellm if your LangGraph app routes its model through litellm — the two compose.

Try it

python examples/react_agent.py     # drives allow / block / approve / deny end-to-end
python tests/test_smoke.py         # offline decision-core test (no langgraph needed)

Metadata

Release files for openguardrails-instrumentation-langgraph 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 openguardrails-instrumentation-langgraph 0.1.1
File Size Uploaded Provenance
openguardrails_instrumentation_langgraph-0.1.1.tar.gz 12.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for openguardrails-instrumentation-langgraph 0.1.1
File Interpreter ABI Platform
openguardrails_instrumentation_langgraph-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / openguardrails_instrumentation_langgraph-0.1.1.tar.gz

Download URL openguardrails_instrumentation_langgraph-0.1.1.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f86b719517aebf79809b948d7e8710ea29a5fb7c2a2f185f88ead11cef314d5f
BLAKE2b-256 checksum
How to use checksums
508113831f251880ce5b5f49280c837c7486cfe4a2070fb60c6abf9c34ba595c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 8, 2026.

Transparency log

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

Download URL openguardrails_instrumentation_langgraph-0.1.1-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcf1db7dc65cd82a45614fb40c52a0fee4ddfc56c0f93c740a07dffaf90cb85d
BLAKE2b-256 checksum
How to use checksums
f494a171a1e85a2f6aef6615ca1f0904038fd06afcc762d91cf20edb0480dddf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 8, 2026.

Transparency log

Security for openguardrails-instrumentation-langgraph 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 openguardrails_instrumentation_langgraph-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 Jul 8, 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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