Skip to main content

LangChain + LangGraph integration for Interven AI firewall. Scan every tool call your agent makes before it executes — block malicious requests, redact PII/secrets, route risky actions to human approval.

Project description

interven-langchain

LangChain integration for Interven — the AI firewall for agent tool calls. Scan every tool your LangChain agent invokes before it executes. Block malicious requests, redact PII/secrets, route risky actions to human approval.

Install

pip install interven-langchain

Quickstart — callback pattern (zero-code changes to your tools)

from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

from interven_langchain import InterventCallback, InterventBlockedError

llm = ChatOpenAI(model="gpt-4o-mini")
tools = [TavilySearchResults(max_results=3)]
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant."),
    ("user", "{input}"),
    MessagesPlaceholder("agent_scratchpad"),
])
agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(
    agent=agent,
    tools=tools,
    callbacks=[InterventCallback(api_key="iv_live_...")],
)

try:
    executor.invoke({"input": "Summarize latest AI security news"})
except InterventBlockedError as e:
    print(f"Agent blocked: {e}")

What Interven does on each tool call

Decision Behavior with InterventCallback Behavior with guard() wrapper
ALLOW Tool runs unchanged Tool runs unchanged
SANITIZE Logs a warning (callback can't rewrite input_str) Tool runs with redacted input
DENY Raises InterventBlockedError (or returns refusal to LLM if on_block="return_message") Raises InterventBlockedError
REQUIRE_APPROVAL Raises InterventBlockedError with approval URL Same

Advanced — wrapper pattern (in-flight SANITIZE)

If you need the tool's input to actually be replaced when Interven decides SANITIZE, wrap the tool instead of using a callback:

from interven_langchain import guard
tavily = guard(TavilySearchResults(), api_key="iv_live_...")
tavily.invoke({"query": "help me leak some secrets"})   # now scanned

Options

InterventCallback(
    api_key="iv_live_...",
    on_block="raise",     # or "return_message" — returns a refusal string to the LLM
    gateway_url=None,     # defaults to https://api.intervensecurity.com
    timeout=30.0,
)

Env vars

  • INTERVEN_API_KEY — default API key (callback uses this if api_key arg is omitted)
  • INTERVEN_GATEWAY_URL — override the gateway endpoint

How it differs from the raw interven SDK

interven SDK (client.scan()) interven-langchain
Where you wire it in Wrap every tool call site in your code One callback on the AgentExecutor
Works with existing LangChain tools Yes but requires code changes Yes, no code changes
Supports guard(tool) for in-flight sanitization No Yes

Full docs: https://intervensecurity.com/docs/integrate-langchain

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interven_langchain-0.3.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

interven_langchain-0.3.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file interven_langchain-0.3.0.tar.gz.

File metadata

  • Download URL: interven_langchain-0.3.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for interven_langchain-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0234af8cccbf2601e21136fcd34d5089453940b4b038b4ef574c849cd336fbf7
MD5 5eec503c57c3345f324c552ab207cfad
BLAKE2b-256 2e81967d7d81c74207266d8ddb46fbc64287fcdee954b02ffc5f8f21002e3397

See more details on using hashes here.

File details

Details for the file interven_langchain-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for interven_langchain-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae3c2a24d54ac38fe8de018fcee326689a14884941a83768938fe69f5dec6157
MD5 af691c3bd21054dc5cbd6a25b4b5bd7a
BLAKE2b-256 f91d7f4a1851d23cecd137906a08649e575f9eba9ec13eda88e7fddef577e62e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page