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) orSIGTERM(only when called from the main thread; passinstall_signal_handlers=Falseto opt out). - An exception propagates out of the wait (
KeyboardInterrupt, network error, anything) — abandon is fired in afinallybefore re-raising. - The Python interpreter exits while the wait is still in flight (an
atexithook 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.
Metadata
Release files for antarraksha-langchain 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| antarraksha_langchain-0.1.5.tar.gz | 12.0 kB | Without provenance | Details for antarraksha_langchain-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| antarraksha_langchain-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for antarraksha_langchain-0.1.5-py3-none-any.whl |
Total release size: 24.0 kB
Release files / antarraksha_langchain-0.1.5.tar.gz
| Download URL | antarraksha_langchain-0.1.5.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
401d1efb4f70cb28b9486d02b2042411f380cad7c07e8c22eeafae33d53d0d28
|
|
BLAKE2b-256 checksum How to use checksums |
a00d0c9f705e2207f62b8953768c71fde19228376d90a76e60da242d298938e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / antarraksha_langchain-0.1.5-py3-none-any.whl
| Download URL | antarraksha_langchain-0.1.5-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d53e2fd4ce24d8199d8d7eeacb49127125a0bd8b85f7a99f1e191e334ec04dc5
|
|
BLAKE2b-256 checksum How to use checksums |
63c46751650ff729bc30d0f39a34c735d82673a3d85cecc381c08b6191e53150
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for antarraksha-langchain 0.1.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.