Skip to main content

langchain-collar

LangChain tools for Collar Guardrail — deterministic pre-trade risk checks for AI trading agents on Robinhood Chain.

PyPI version PyPI downloads Python versions License: MIT


What is this?

This package wraps the Collar Guardrail MCP server as native LangChain tools. Any LangChain agent can evaluate proposed trades against a deterministic risk policy before executing them — with allow / warn / deny verdicts, a 0–100 risk score, and a tamper-evident SHA-256 audit hash.

If you're building a trading agent that needs to respect rate limits, tier ceilings, honeypot checks, or market-hours rules, these tools enforce those constraints outside your agent's own runtime.


Installation

pip install langchain-collar

Requires Python 3.10+ and langchain-core>=0.3.0.


Quick Start

Add tools to a LangChain agent

from langchain_collar import get_tools
from langchain.agents import create_agent

tools = get_tools()
agent = create_agent("gpt-4o", tools)

result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": (
            "Before executing a 10 NVDA buy from wallet "
            "0x1234567890abcdef1234567890abcdef12345678, "
            "run a pre-trade risk check."
        ),
    }]
})
print(result)

Or call a tool directly

from langchain_collar import evaluate_trade

verdict = evaluate_trade.invoke({
    "wallet": "0x1234567890abcdef1234567890abcdef12345678",
    "asset": "NVDA",
    "contract_address": "0x<official_registry_address>",
    "side": "buy",
    "amount": 10.0,
})
print(verdict)

Available Tools

Tool Description
evaluate_trade Call before every trade. Returns allow / warn / deny, reasons, risk score, and audit hash. Treat deny as a hard stop. Honeypot findings (severity=danger) from check_token_safety automatically force a deny regardless of other checks.
check_token_safety Honeypot / contract safety check for any ERC-20 token. Returns severity (safe / warn / danger) plus a sell-simulation result. When severity=danger, the next evaluate_trade for the same contract is auto-denied.
simulate_balance Read-only simulation of a wallet's ERC-20 balance after a hypothetical trade. No transaction is sent.
get_supported_assets The official Robinhood Chain asset registry. Resolve a symbol to its canonical contract address before calling evaluate_trade.
verify_audit_trail Recomputes every past decision's SHA-256 hash and verifies the hash-chain links. Returns healthy=true only if nothing was tampered with.

How It Works

Each tool is a thin wrapper around the Collar Guardrail MCP server at:

https://backendai-x4m1.onrender.com/mcp-http/mcp

The MCP transport is Streamable HTTP (protocol version 2025-06-18). No API key is required for the MCP endpoint — every call is evaluated at a fixed Tier 1 ceiling ($5,000 notional).

For higher limits ($25K / $100K), use the REST API with wallet-signature authentication. See the Collar agent docs.


Decision Semantics

Decision Meaning Action
allow Policy passed. Safe to execute.
warn Policy soft-violated. Trade may proceed but is flagged. Reasons prefixed with ADVISORY: are non-blocking.
deny Policy hard-violated. Do not execute. Reasons are blocking. Honeypot findings (severity=danger) always produce a deny.

Safety rule: If a verdict contains an error key, no verdict was produced. Treat it as a hard stop. If decision == "deny", do not execute the trade.


Example: Full Pre-Trade Flow

import json

from langchain_collar import (
    evaluate_trade,
    get_supported_assets,
    check_token_safety,
)

# 1. Resolve the symbol to its canonical contract address
assets = get_supported_assets.invoke({})
print(assets)  # → list of {symbol, contract_address, is_native}

# 2. Check the token for honeypot risk BEFORE evaluating the trade
safety = json.loads(check_token_safety.invoke({
    "contract_address": "0x<token_address>",
}))
if safety.get("severity") == "danger":
    raise RuntimeError(
        f"Token is flagged as dangerous: {safety.get('risk_factors')}"
    )

# 3. Run the pre-trade risk check
verdict = evaluate_trade.invoke({
    "wallet": "0x1234567890abcdef1234567890abcdef12345678",
    "asset": "NVDA",
    "contract_address": "0x<official_registry_address>",
    "side": "buy",
    "amount": 10.0,
    "max_slippage_bps": 100,
})

if '"decision": "deny"' in verdict:
    raise RuntimeError("Trade denied by Collar Guardrail")

# Proceed with the trade only if the verdict is allow or warn

Paid Tier (x402)

For high-volume agent traffic, Collar exposes an x402 payment endpoint at POST /api/x402/analyze$0.01 USDG per call on Robinhood Chain, no signup required. See the x402 discovery document.


Configuration

The package talks to the public Collar MCP endpoint by default. To self-host Collar, override the base URL:

import langchain_collar.tools as tools

tools._BASE_URL = "https://your-colar-instance.example.com"
tools._MCP_ENDPOINT = f"{tools._BASE_URL}/mcp-http/mcp"

Resource URL
Collar Guardrail (UI) https://collar-b46l.onrender.com
Agent Integration Guide https://collar-b46l.onrender.com/agent-docs.html
MCP Server Card https://backendai-x4m1.onrender.com/.well-known/mcp/server-card.json
MCP Registry io.github.aiguardrail/backend
PyPI https://pypi.org/project/langchain-collar/

Contributing

Issues and pull requests are welcome. Please open an issue first to discuss larger changes.


Disclosure

Collar is independent third-party infrastructure. Not built, operated, or endorsed by Robinhood. COLR is a separate token, not affiliated with Robinhood Markets, Inc.


License

MIT — see LICENSE.

Release files for langchain-collar 1.0.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 langchain-collar 1.0.1
File Size Uploaded
langchain_collar-1.0.1.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-collar 1.0.1
File Interpreter ABI Platform
langchain_collar-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size:13.2 kB

Release files / langchain_collar-1.0.1.tar.gz

Download URL langchain_collar-1.0.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3527b74876b257dd221ba8325d4f02881ca5874f99e8f28fd95a7ce79746e6f6
BLAKE2b-256 checksum
How to use checksums
dcbbc177f041563bef1d3b916946098da5c1f34fa39783ef7762c4d42095e456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

Release files / langchain_collar-1.0.1-py3-none-any.whl

Download URL langchain_collar-1.0.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6db1606797710619a802b6b5d86e1cff9110376648883f8dbf7badb3a4b98483
BLAKE2b-256 checksum
How to use checksums
0d5e9de417e35be17123912ab92c115f72f665f0191854f7f0bb822a9308a6c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

Release history Release notifications | RSS feed

1.0.4

2 release files

This release

1.0.1 This release

2 release files

1.0.0

2 release files

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