How to Build a compliance checking Agent Using CrewAI in Python for insurance
A compliance checking agent for insurance reviews policy documents, claim notes, customer communications, and underwriting outputs against internal rules and regulatory requirements. It matters because a missed disclosure, an inconsistent clause, or a non-compliant recommendation can create regulatory exposure, customer harm, and expensive remediation.
Architecture
- •Input collector
- •Pulls policy text, claim summaries, email drafts, or underwriting decisions from your system of record.
- •Compliance rule set
- •Encodes insurer-specific checks: required disclosures, prohibited language, jurisdiction rules, retention requirements.
- •CrewAI agent
- •Uses a focused role like “Insurance Compliance Reviewer” to inspect content and produce structured findings.
- •Task runner
- •Executes one or more review tasks with clear outputs: pass/fail, violations, severity, and remediation.
- •Audit logger
- •Stores the input hash, model output, timestamp, reviewer version, and decision trail for regulators and internal audit.
- •Human escalation path
- •Routes high-risk findings to compliance staff when confidence is low or the issue impacts regulated communications.
Implementation
1) Install dependencies and define the compliance scope
Use CrewAI for orchestration and keep the scope narrow. For insurance work, that usually means one line of business at a time: claims correspondence, policy wording review, or underwriting explanations.
pip install crewai crewai-tools pydantic
Start with a small rule set. In production you would load this from a versioned policy repository rather than hardcoding it.
2) Build a structured output model for auditability
You want machine-readable results, not free-form prose. That makes it easier to persist findings into your GRC or case management system.
from pydantic import BaseModel
from typing import List
class ComplianceFinding(BaseModel):
rule_id: str
severity: str
issue: str
recommendation: str
class ComplianceReport(BaseModel):
overall_status: str
findings: List[ComplianceFinding]
This pattern gives you stable downstream parsing. It also helps with evidence packs during audits because each finding is explicit.
3) Create the CrewAI agent and task
CrewAI’s Agent, Task, and Crew classes are enough for a first production-grade workflow. The key is to constrain the agent with a precise role and expected output.
from crewai import Agent, Task, Crew, Process
compliance_agent = Agent(
role="Insurance Compliance Reviewer",
goal="Review insurance content for regulatory and internal policy compliance",
backstory=(
"You are an insurance compliance specialist. "
"You check customer-facing and internal insurance text for missing disclosures, "
"prohibited claims language, unfair wording, jurisdiction issues, and auditability."
),
verbose=True,
)
review_task = Task(
description=(
"Review the following insurance communication for compliance issues:\n\n"
"{document_text}\n\n"
"Check for missing mandatory disclosures, misleading statements, "
"jurisdiction-specific risks, data handling concerns, and unclear remediation steps."
),
expected_output=(
"A structured compliance report with overall_status and findings. "
"Each finding must include rule_id, severity, issue, and recommendation."
),
agent=compliance_agent,
)
The important part here is that the task asks for specific categories of risk relevant to insurance. That keeps the output useful for legal review instead of generic commentary.
4) Run the crew and serialize results for audit
For single-agent review workflows in insurance, Process.sequential is usually enough. If you later add a legal reviewer or an escalation agent, you can extend the crew without changing the input contract.
import json
crew = Crew(
agents=[compliance_agent],
tasks=[review_task],
process=Process.sequential,
verbose=True,
)
document_text = """
We will approve your claim within 24 hours in all cases.
Your personal data may be shared with partners without limitation.
This notice applies to all jurisdictions.
"""
result = crew.kickoff(inputs={"document_text": document_text})
print(result)
with open("compliance_audit_log.json", "w") as f:
json.dump(
{
"input": document_text,
"output": str(result),
},
f,
indent=2,
)
If you need stricter structure than plain text output from CrewAI’s default response path, wrap this with your own parser or use downstream validation against your Pydantic schema. In regulated workflows that extra validation step is not optional.
Production Considerations
- •Keep data residency explicit
- •Insurance data often crosses jurisdictional boundaries. Pin execution to approved regions and avoid sending PII outside your controlled environment.
- •Log every decision path
- •Store prompt version, rule version, input hash, output hash, timestamp, and human override status. Regulators care about traceability more than model elegance.
- •Add guardrails before auto-action
- •This agent should recommend fixes or escalate issues; it should not rewrite approved policy language or send customer communications without review.
- •Monitor false negatives by line of business
- •A model that performs well on claims letters may fail on life insurance disclosures or surplus lines notices. Track metrics per product and jurisdiction.
Common Pitfalls
- •Using one generic prompt for all insurance domains
- •Claims handling rules are not the same as underwriting disclosures or policy issuance notices. Split by use case and jurisdiction.
- •Treating free-text output as sufficient evidence
- •A paragraph saying “looks compliant” is useless in audit. Require structured findings with rule IDs and severity levels.
- •Ignoring versioning of rules and prompts
- •If a regulator asks why something passed last month but fails today, you need exact versions of both the policy rules and the agent prompt.
- •Letting the agent decide final compliance status automatically
- •The agent should flag risk; compliance teams should approve final decisions for high-impact communications.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit