LangChain Integration

Official LangChain integration for Compliable. Add GDPR, CCPA, and HIPAA compliance checking to your AI agents with three production-ready tools.

Overview

The langchain-compliable package integrates the Compliable API with LangChain, enabling AI agents to automatically check legal documents for regulatory compliance.

The package provides three specialized compliance tools that can be used directly, added to LangChain agents, or integrated into LangGraph workflows.

Available Tools

  • check_gdpr_compliance — EU General Data Protection Regulation
  • check_ccpa_compliance — California Consumer Privacy Act
  • check_hipaa_compliance — Health Insurance Portability and Accountability Act

Installation

Install the package via pip:

Install via pip
pip install langchain-compliable

Set your Compliable API key as an environment variable:

.env
# .env
COMPLIABLE_API_KEY=cpbl_your_api_key_here

Get your API key from the Compliable Dashboard.

Quick Start

Here's a simple example of checking GDPR compliance:

Python
import asyncio
from langchain_compliable import check_gdpr_compliance

async def check_policy():
    result = await check_gdpr_compliance.ainvoke({
        "content": "We collect user data and may share it with third parties.",
        "jurisdiction": "EU",
        "document_type": "privacy_policy"
    })
    print(result)

asyncio.run(check_policy())

Usage Patterns

1. Direct Tool Usage

Use individual compliance tools directly in your code:

Python - Direct Tool Usage
from langchain_compliable import (
    check_gdpr_compliance,
    check_ccpa_compliance,
    check_hipaa_compliance
)

# GDPR compliance check
gdpr_result = await check_gdpr_compliance.ainvoke({
    "content": "Privacy policy text here...",
    "jurisdiction": "EU",
    "articles": ["13", "14"],
    "focus": ["data_controller", "user_rights"],
    "document_type": "privacy_policy"
})

# CCPA compliance check
ccpa_result = await check_ccpa_compliance.ainvoke({
    "content": "Privacy policy text here...",
    "business_type": "for-profit",
    "categories": ["right-to-know", "right-to-delete"],
    "document_type": "privacy_policy",
    "industry": "saas"
})

# HIPAA compliance check
hipaa_result = await check_hipaa_compliance.ainvoke({
    "content": "Patient communication text...",
    "covered_entity": True,
    "safeguards": ["privacy_rule", "security_rule"],
    "document_type": "patient_communication"
})

2. LangChain Agents

Create AI agents that autonomously select and use appropriate compliance tools:

Python - LangChain Agent
from langchain_openai import ChatOpenAI
from langchain.agents import create_openai_tools_agent, AgentExecutor
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_compliable import CompliableToolkit

# Setup LLM and tools
llm = ChatOpenAI(model="gpt-4o", temperature=0)
toolkit = CompliableToolkit()
tools = toolkit.get_tools()  # Returns all three compliance tools

# Create compliance expert agent
prompt = ChatPromptTemplate.from_messages([
    ("system", """You are a legal compliance expert specializing in data
    protection regulations. Use the available tools to check documents for
    GDPR, CCPA, and HIPAA compliance. Provide clear, actionable recommendations."""),
    ("human", "{input}"),
    MessagesPlaceholder("agent_scratchpad"),
])

agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# Agent autonomously selects appropriate compliance tools
result = executor.invoke({
    "input": "Review this privacy policy for our healthcare SaaS operating in EU and California: [policy text here]"
})

print(result["output"])

The agent will analyze the input, determine which compliance frameworks apply, and automatically call the appropriate tools to generate a comprehensive compliance report.

3. LangGraph Workflows

Build complex multi-step compliance workflows:

Python - LangGraph Workflow
from langgraph.graph import StateGraph, MessagesState
from langgraph.prebuilt import ToolNode
from langchain_compliable import CompliableToolkit

toolkit = CompliableToolkit()
tools = toolkit.get_tools()

# Create workflow with compliance checking
workflow = StateGraph(MessagesState)
workflow.add_node("compliance_check", ToolNode(tools))
workflow.add_node("analysis", analyze_violations)
workflow.add_node("recommendations", generate_recommendations)

# Define workflow edges
workflow.set_entry_point("compliance_check")
workflow.add_edge("compliance_check", "analysis")
workflow.add_edge("analysis", "recommendations")

app = workflow.compile()

# Run multi-step compliance workflow
result = app.invoke({
    "messages": [("user", "Check our privacy policy for all applicable regulations")]
})

Common Use Cases

Automated Policy Review

Agent reviews draft privacy policies and terms of service for compliance violations before publication.

Multi-Framework Analysis

Agent checks documents against multiple regulations (GDPR, CCPA, HIPAA) for international companies.

Iterative Policy Improvement

Agent suggests fixes, user makes changes, agent rechecks — repeat until fully compliant.

Compliance Audit Trail

Store compliance check results with timestamps for regulatory audit purposes.

Tool Reference

check_gdpr_compliance

Checks content for GDPR compliance violations.

Input Parameters

  • content (required) — Text to check for compliance
  • jurisdiction (optional) — EU, UK, CH, NO, IS, or LI
  • articles (optional) — List of specific GDPR articles to check
  • focus (optional) — Focus areas: data_controller, lawful_basis, user_rights, etc.
  • document_type (optional) — privacy_policy, terms_of_service, etc.
  • industry (optional) — saas, healthcare, finance, etc.

check_ccpa_compliance

Checks content for CCPA compliance violations.

Input Parameters

  • content (required) — Text to check for compliance
  • business_type (optional) — for-profit, service-provider, or third-party
  • categories (optional) — List of CCPA categories: right-to-know, right-to-delete, etc.
  • focus (optional) — Focus areas: consumer_rights, sale_disclosure, etc.
  • document_type (optional) — privacy_policy, terms_of_service, etc.
  • industry (optional) — saas, healthcare, finance, etc.

check_hipaa_compliance

Checks content for HIPAA compliance violations.

Input Parameters

  • content (required) — Text to check for compliance
  • covered_entity (optional) — Boolean: is this for a covered entity?
  • safeguards (optional) — List: administrative, physical, technical
  • focus (optional) — Focus areas: privacy_rule, security_rule, breach_notification, etc.
  • document_type (optional) — privacy_policy, patient_communication, etc.
  • industry (optional) — healthcare (typically)

Error Handling

The package provides specific exception types for different error scenarios:

Python - Error Handling
from langchain_compliable import check_gdpr_compliance
from langchain_compliable.exceptions import (
    CompliableAuthenticationError,
    CompliableQuotaExceededError,
    CompliableRateLimitError,
    CompliableValidationError,
)

try:
    result = await check_gdpr_compliance.ainvoke({
        "content": "Privacy policy...",
        "jurisdiction": "EU"
    })
except CompliableAuthenticationError:
    print("Invalid API key. Check your COMPLIABLE_API_KEY environment variable.")
except CompliableQuotaExceededError:
    print("Monthly quota exceeded. Upgrade your plan at https://compliable.dev/#pricing")
except CompliableRateLimitError as e:
    print(f"Rate limit hit. Retry after {e.retry_after} seconds.")
except CompliableValidationError as e:
    print(f"Invalid request: {e.message}")

Exception Types

  • CompliableAuthenticationError — Invalid API key (401)
  • CompliableQuotaExceededError — Monthly quota limit hit (403)
  • CompliableRateLimitError — Rate limit exceeded (429)
  • CompliableValidationError — Request validation failed (400, 413)

Resources

Package Documentation

Official LangChain documentation for the Compliable integration.

View on LangChain Docs →

PyPI Package

Install via pip and view package details on PyPI.

View on PyPI →

GitHub Repository

View source code, report issues, and contribute to the project.

View on GitHub →

API Reference

Complete API documentation for the Compliable REST API.

View API Reference →

Need Help?

If you encounter issues or have questions about the LangChain integration: