Skip to content

LangChain Integration Sketch

LangChain middleware can control agent execution around model calls, tool calls, guardrails, and human-in-the-loop paths. Planisphere belongs at the tool/action edge: before an AI workflow sends, files, exports, deletes, buys, deploys, or otherwise mutates the real world.

References:

  • https://docs.langchain.com/oss/python/langchain/guardrails
  • https://docs.langchain.com/oss/python/langchain/middleware/overview

Pattern

  1. Wrap sensitive tools or workflow actions.
  2. Convert the tool/action intent into proposed_action.
  3. Call Planisphere.
  4. Continue, pause, or block based on the decision.
  5. Store the returned evidence packet href in your workflow state.

Minimal Wrapper

The checked copyable helper is in docs/examples/python/planisphere_gate.py. Use it inside middleware or around tools that mutate customer systems.

from planisphere_gate import (
    PlanisphereBlocked,
    PlanisphereClient,
    PlanisphereNeedsReview,
    route_for_review,
)


client = PlanisphereClient(
    base_url="https://api.planisphere.ooo",
    api_key="<tenant-api-key>",
)


def gated_tool_call(tool_name: str, args: dict, call_tool):
    try:
        client.require_allow(
            surface="langchain",
            proposed_action=f"Execute {tool_name} with externally visible side effects.",
            source_key=args.get("source_key", f"langchain:{tool_name}"),
            law_context=args["law_context"],
        )
    except PlanisphereNeedsReview as review:
        return route_for_review(review.decision)
    except PlanisphereBlocked:
        raise

    return call_tool(**args)

Store route_for_review(...) in LangGraph/LangChain state so the workflow can resume after the reviewer's decision is recorded with POST /v1/reviews (body: {"pack": "law", "action_key": ..., "reviewer": ..., "decision": "approved" | "rejected" | "escalated"}).