Skip to main content

antarraksha-langchain

Antarraksha AI Agent Enforcement SDK for LangChain.

Installation

pip install antarraksha-langchain

Quick Start

Attach Antarraksha as a callback handler on your LLM. Registration happens automatically on first use — no login, no API key, no signup required.

from antarraksha_langchain import AntarrakshaCallbackHandler
from langchain_anthropic import ChatAnthropic

handler = AntarrakshaCallbackHandler(agent_id="my-langchain-agent")

llm = ChatAnthropic(model="claude-sonnet-4-5", callbacks=[handler])
print(llm.invoke("Hello").content)

Run your agent normally — every LLM call, tool call, and chain call is now enforced against Antarraksha policy.

Tool Wrapping (optional)

Wrap individual LangChain tools for inline enforcement:

from langchain_community.tools import ShellTool
from antarraksha_langchain import AntarrakshaSafeTool, AntarrakshaClient

client = AntarrakshaClient(agent_id="my-langchain-agent")
client.register()

safe_shell = AntarrakshaSafeTool(wrapped_tool=ShellTool(), antarraksha_client=client)
safe_shell.run("ls")

Parameters

Parameter Default Description
agent_id None Unique identifier for your agent. Triggers auto-registration on first use.
base_url "https://antarraksha.ai" Antarraksha endpoint. Override for self-hosted / dev.
passport_id None Optional pre-issued passport ID (e.g. ANTK-PASS-xxx).
sdk_key None Optional pre-issued SDK key. If omitted and agent_id is set, the SDK auto-registers and obtains one.
fail_closed True If True, deny on enforcement-server unreachable. Set False for fail-open during early integration.
block_on_deny True If True, raise PermissionError when Antarraksha returns DENY.

Enforcement Behavior

  • on_llm_start fires before every LLM call. DENY raises PermissionError.
  • on_tool_start fires before every tool invocation. DENY raises PermissionError.
  • on_chain_start fires for every chain run (informational; no enforcement halt).
  • Every call is logged and visible at https://antarraksha.ai/registry.

Human-in-the-loop Escalation (long-poll + auto-abandon)

When Antarraksha holds a tool call for 4-eyes review, the SDK exposes a long-poll helper that blocks until the operator decides — and automatically gives up (fires POST /sdk/escalation/:id/abandon) the moment the caller cancels. This collapses the 60-second server-side silence-sweep window to roughly one second, so the operator queue drains immediately when the SDK side walks away.

import threading
from antarraksha_langchain import AntarrakshaClient

client = AntarrakshaClient(agent_id="my-agent")
client.register()

cancel = threading.Event()
result = client.wait_escalation(
    "esc-123",
    timeout_ms=30_000,
    cancel_event=cancel,   # set this from your AbortController / Ctrl-C handler
)
print(result["status"], result.get("finalDecision"))

wait_escalation auto-fires POST /sdk/escalation/:id/abandon when any of these happen mid-wait:

  • cancel_event.set() is called (your AbortController / request-timeout).
  • The process receives SIGINT (Ctrl-C) or SIGTERM (only when called from the main thread; pass install_signal_handlers=False to opt out).
  • An exception propagates out of the wait (KeyboardInterrupt, network error, anything) — abandon is fired in a finally before re-raising.
  • The Python interpreter exits while the wait is still in flight (an atexit hook fires the abandon as a last-chance signal).

The helper is idempotent against the server (the row CAS-flips PENDING → ABANDONED + final_decision=BLOCK exactly once); calling client.abandon_escalation("esc-123") directly is safe at any time.

Corporate Network Note

If you're behind a corporate TLS-inspection proxy and see SSLCertVerificationError, install:

pip install pip-system-certs

This makes Python trust your Windows / macOS system certificate store.

Download files

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

Source Distribution

antarraksha_langchain-0.1.5.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

antarraksha_langchain-0.1.5-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file antarraksha_langchain-0.1.5.tar.gz.

File metadata

  • Download URL: antarraksha_langchain-0.1.5.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for antarraksha_langchain-0.1.5.tar.gz
Algorithm Hash digest
SHA256 401d1efb4f70cb28b9486d02b2042411f380cad7c07e8c22eeafae33d53d0d28
MD5 de3c472d55733104b92768b1c3940e8b
BLAKE2b-256 a00d0c9f705e2207f62b8953768c71fde19228376d90a76e60da242d298938e7

See more details on using hashes here.

File details

Details for the file antarraksha_langchain-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for antarraksha_langchain-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d53e2fd4ce24d8199d8d7eeacb49127125a0bd8b85f7a99f1e191e334ec04dc5
MD5 71358f24a72e1e88c613ed2ea9b0d247
BLAKE2b-256 63c46751650ff729bc30d0f39a34c735d82673a3d85cecc381c08b6191e53150

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