CL
Clausgap
/Docs

LangChain & LangGraph

bash
pip install clausgap-langchain
ℹ

Private beta. The SDK packages aren't on the public registries yet. Access comes with onboarding — email hello@clausgap.dev.

Uses direct-mode policy evaluation (POST /v1/evaluate on the control plane) rather than routing HTTP through the proxy, so it works with any tool — not just HTTP-based ones. Three ways to wire it in, pick whichever fits how your agent is built:

python
from langchain_core.tools import tool
from clausgap_langchain import ClausgapCallbackHandler, guarded_tool, guarded_node

# ── Option 1: Callback handler (hooks into chain/agent lifecycle) ──────────
handler = ClausgapCallbackHandler(
    proxy_url="http://localhost:8443",
    signing_secret=os.environ["CLAUSGAP_HMAC_SECRET"],
    agent_role="support_agent",
)
# Attach to any LangChain chain or agent
chain.invoke({"input": "..."}, config={"callbacks": [handler]})


# ── Option 2: @guarded_tool decorator ─────────────────────────────────────
@guarded_tool(
    control_url="http://localhost:8080",
    api_key=os.environ["CLAUSGAP_API_KEY"],
    agent_role="support_agent",
)
@tool
def lookup_customer(customer_id: str) -> dict:
    """Look up a customer record."""
    return api.get(f"/customers/{customer_id}")


# ── Option 3: @guarded_node for LangGraph ─────────────────────────────────
from clausgap_langchain import guarded_node
from langgraph.graph import StateGraph

@guarded_node(
    control_url="http://localhost:8080",
    api_key=os.environ["CLAUSGAP_API_KEY"],
    agent_role="analyst",
    tool_name="query_database",
)
def query_database(state):
    return {"result": db.execute(state["query"])}
ℹ

@guarded_tool works whichever order it's stacked with @tool — it detects a real LangChain BaseTool and rebinds its underlying function in place, so the tool keeps working with agent executors and bind_tools() either way.

Escrow holds

A policy's escrow rule works the same way here as everywhere else — see the escrow flow →

Use the agent's own key

Give the integration the agent's own key — registered with POST /v1/keyless/api-keys, the same key the proxy accepts — and set CLAUSGAP_TENANT_ID to your tenant ID. The key then fixes the agent's role and ID (the configured role must match it) and can only evaluate tool calls: it can't change policies or issue keys. A tenant API key also works, but lets the agent name any role, and Discovery Mode only lets calls through for agent keys. Set CLAUSGAP_ENVIRONMENT and CLAUSGAP_SCOPES to match your proxy's, if you use them. See agent keys →