Integration Guide
How to Add Governance to LangChain Agents
DataCrawl adds governance to LangChain agents without requiring you to rebuild them.
Your agents call the DataCrawl evaluation API before executing actions. DataCrawl evaluates against policy, handles approvals if needed, and returns a decision. Your agent proceeds or waits.
Why LangChain Agents Need Governance
LangChain agents are powerful because they can chain tools together and make decisions about what to do next. That power becomes a problem in production when:
- Multiple agents operate over the same data and systems (policy becomes fragmented)
- An agent can take actions that have real consequences (transfers, deletes, communications)
- You need to be able to pause and review before a high-risk action executes
- You need to prove to compliance and audit teams that actions were authorized
LangChain's built-in guardrails constrain what the agent hallucinates. DataCrawl governance constrains what authorized agents are allowed to do.
How It Works
The architecture is simple:
- Your LangChain agent decides to take an action (e.g., issue a refund).
- Before calling the tool, your agent calls DataCrawl's evaluation endpoint with the action payload.
- DataCrawl evaluates the action against policies and returns a decision: ALLOW, REQUIRE_APPROVAL, or DENY.
- If ALLOW, you receive an execution token. Your agent proceeds with the tool call.
- If REQUIRE_APPROVAL, the action waits in DataCrawl's queue for human review. Your agent can check back later or wait.
- If DENY, your agent is notified and the action is logged. No execution happens.
Integration: The API Call
Your LangChain agent makes this call before executing a tool:
POST /api/evaluate
{
"agent_id": "agent_123_refund_processor",
"action": {
"action_type": "issue_refund",
"customer_id": "cust_456",
"amount_cents": 500000,
"reason": "Customer requested return"
}
}
Response:
{
"decision": "ALLOW",
"execution_token": "exec_token_xyz",
"trace_id": "trace_abc123"
}
// Now your agent can proceed:
refund_tool.invoke({
customer_id: "cust_456",
amount_cents: 500000,
execution_token: "exec_token_xyz"
})Integration Pattern in LangChain
Wrap your tool calls with governance checks:
from langchain.agents import Tool
from datacrawl import DataCrawlClient
dc = DataCrawlClient(api_key="your_api_key")
async def issue_refund_with_governance(
customer_id: str,
amount_cents: int,
reason: str
) -> str:
# Call DataCrawl first
decision = await dc.evaluate(
agent_id="refund_processor",
action={
"action_type": "issue_refund",
"customer_id": customer_id,
"amount_cents": amount_cents,
"reason": reason
}
)
if decision["decision"] == "DENY":
return f"Action blocked: {decision['reason']}"
if decision["decision"] == "REQUIRE_APPROVAL":
return f"Action pending approval. Trace: {decision['trace_id']}"
# ALLOW - proceed with tool call
result = await refund_service.issue_refund(
customer_id=customer_id,
amount_cents=amount_cents,
execution_token=decision['execution_token']
)
return result
# Register with LangChain
refund_tool = Tool(
name="issue_refund",
func=issue_refund_with_governance,
description="Issue a refund to a customer"
)
agent.tools.append(refund_tool)Policy Definition
Define policies in DataCrawl once. They apply to all your LangChain agents (and any other agents using DataCrawl):
Example policy: Refunds under $100 are auto-approved. Refunds $100–$1000 require manager approval. Refunds over $1000 require director approval.
{
"rule_type": "business_threshold",
"triggers": [
{
"condition": "field_between",
"field": "amount_cents",
"min": 0,
"max": 10000,
"outcome": "allow"
},
{
"condition": "field_between",
"field": "amount_cents",
"min": 10001,
"max": 100000,
"outcome": "require_approval"
},
{
"condition": "field_between",
"field": "amount_cents",
"min": 100001,
"max": 999999999,
"outcome": "escalate"
}
]
}What You Get
- Unified Policy: One policy applies to all LangChain agents. No duplication.
- Instant Policy Updates: Change policy in DataCrawl dashboard. All agents enforce the new policy immediately.
- Approval Workflows: High-risk actions pause and wait for human approval. Built-in, no custom dashboard needed.
- Audit Trail: Every agent action is logged with full context, who approved it, what policy version was used.
- No Agent Rebuild: Your LangChain agents don't change. You just add a governance check before executing tools.
Common Questions
Does this add latency?
DataCrawl evaluation typically takes 10–50ms. For most LangChain agent workflows, this is negligible compared to LLM call latency. For high-frequency operations, you can batch governance calls.
What if DataCrawl is down?
You can configure a fallback policy. Options: fail open (allow by default), fail closed (deny by default), or queue and retry locally.
Can I use this with other frameworks?
Yes. DataCrawl works with AutoGen, CrewAI, n8n, custom Python agents, and any system that can make an HTTP call. You write the integration once per framework.
How do I handle approval workflows?
When a decision is REQUIRE_APPROVAL, DataCrawl queues the action. Humans review and approve/deny via the DataCrawl dashboard or API. Once approved, your agent can query the status or subscribe to webhooks.