integrate-arcjet-guard-langchain-py

Integrate Arcjet Guard security policies into Python LangChain tools and agents.

1|Updated Apr 8, 2026
One-click install
npx skills add https://github.com/arcjet/arcjet-plugin --skill integrate-arcjet-guard-langchain-py-arcjet
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: integrate-arcjet-guard-langchain-py
Source: https://github.com/arcjet/arcjet-plugin/tree/main/plugins/arcjet/skills/integrate-arcjet-guard-langchain-py
Command: npx skills add https://github.com/arcjet/arcjet-plugin --skill integrate-arcjet-guard-langchain-py-arcjet

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires arcjet, langchain-core, langchain, langgraph.

What problem does it solve? Python LangChain agents can call risky tools, accept prompt-injected input, and leak PII without any enforcement layer. This Skill guides you through adding Arcjet Guard to LangChain so tool calls are rate-limited, denied, or observed according to explicit policies. ## Core Features & Use Cases - Guard individual tools: Wrap any BaseTool you call yourself with guard_tool so DENY decisions raise ArcjetToolDeniedError before execution. - Policy-driven agents: Attach ArcjetMiddleware with ToolPolicy entries to create_agent so model-selected tools are gated by rules like TokenBucket rate limits. - Inbound screening and observability: Screen user messages for prompt injection with core guard() before ainvoke, and record decisions with ArcjetCaptureHandler for audit. - Use Case: You have a LangChain agent with a send_email tool. Wrap it with guard_tool and a per-user TokenBucket rule so each user can send at most 10 emails per minute, and screen inbound messages for prompt injection before invoking the agent. ## Quick Start Ask your AI agent to add Arcjet Guard to my Python LangChain agent by wrapping the send_email tool with guard_tool and a per-user rate limit.

Frequently Asked Questions about integrate-arcjet-guard-langchain-py

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add Arcjet Guard to a LangChain tool in Python?▼

Wrap the BaseTool with guard_tool from arcjet.guard.langchain, passing your guard client, an action label, and rules such as a TokenBucket rate limit. DENY decisions raise ArcjetToolDeniedError, and the wrapped result is still a BaseTool.

How do I rate limit tools in a LangChain create_agent agent?▼

Attach ArcjetMiddleware to create_agent with a ToolPolicy per tool name, defining rules like TokenBucket keyed on the authenticated user. Pass the same tools sequence to both create_agent and the middleware so policy typos are refused at construction.

Does this work with LangChain JS or LangGraph JS?▼

No. This module is Python-only arcjet.guard.langchain. LangChain JS uses @arcjet/guard/langchain/v1 with createAgent and wrapToolCall, and LangGraph JS uses @arcjet/guard/langgraph/v1 with StateGraph and ToolNode.

Can ArcjetCaptureHandler block a LangChain tool call?▼

No. LangChain ignores callback return values, so ArcjetCaptureHandler and ArcjetAsyncCaptureHandler only record decisions. Enforcement must come from guard_tool, ArcjetMiddleware, or core guard() calls.

How do I screen inbound messages for prompt injection before agent.ainvoke?▼

There is no inbound helper, so call core aj.guard with a DetectPromptInjection rule on the user text before invoking the agent. Check decision.conclusion for DENY and decision.has_failed_open() if the call site must fail closed.

What Python packages are required for Arcjet LangChain integration?▼

Install PyPI arcjet 1.0.0 with the langchain extra for guard_tool and capture handlers, or the langchain-agents extra for ArcjetMiddleware and ToolPolicy. Python 3.10 or newer is required.