Overview
This example demonstrates integrating Agent Control with CrewAI to provide multi-layer security for a customer support agent:- Agent Control for security/compliance — PII detection, unauthorized access blocking
- CrewAI Guardrails for quality validation — length, tone, structure
To run the full example yourself, visit the source on GitHub:
CrewAI Example
Why This Matters
Customer support agents (human or AI) can accidentally:- Leak PII (emails, phones, SSNs, credit cards) in responses or logs
- Access other users’ data when they shouldn’t
- Disclose passwords, credentials, or admin information
- Violate GDPR, CCPA, PCI-DSS compliance requirements
| Layer | Stage | What It Does |
|---|---|---|
| Layer 1 | PRE-execution | Block unauthorized data access requests before processing |
| Layer 2 | POST-execution | Block PII that the LLM accidentally generates in tool responses |
| Layer 3 | Final output | Catch PII in the final crew output (orchestration bypass protection) |
Prerequisites
1. Start the Agent Control Server
Expected Behavior
Scenario 1: Unauthorized Access — PRE blocks immediately
Scenario 1: Unauthorized Access — PRE blocks immediately
Scenario 2: PII Leakage — POST blocks output
Scenario 2: PII Leakage — POST blocks output
Scenario 2.5: Quality Issues — CrewAI Guardrails retry
Scenario 2.5: Quality Issues — CrewAI Guardrails retry
Scenario 3: Orchestration Bypass — Final output validation
Scenario 3: Orchestration Bypass — Final output validation
Agent Control vs CrewAI Guardrails
| Aspect | Agent Control | CrewAI Guardrails |
|---|---|---|
| Purpose | Security / Compliance | Quality / Format |
| Checks | PII, unauthorized access | Length, tone, structure |
| On Failure | Block immediately ❌ | Retry with feedback ✅ |
| Retries | No (0) | Yes (up to 3) |
| Examples | Email, SSN, unauthorized | Too short, unprofessional |
How It Works
The @control() decorator with CrewAI tools
CrewAI tools are synchronous, but the @control() decorator is async. Use an asyncio.run() wrapper:
Three-layer validation flow
Why three layers?- Layers 1 & 2 protect at the tool boundary (standard
@control()usage) - Layer 3 protects against orchestration bypass — when CrewAI’s agent generates its own response containing PII after a tool was blocked
Control configuration
Architecture
Files
| File | Description |
|---|---|
content_agent_protection.py | Main CrewAI crew with @control() integration |
setup_content_controls.py | One-time setup for controls and policy |
pyproject.toml | Dependencies |
Troubleshooting
"event loop already running" error
"event loop already running" error
CrewAI tools are sync by default, but
@control requires async. Use an asyncio.run() wrapper:Control not triggering
Control not triggering
Most common cause: the setup script was not run.Also verify the tool name is set on the async function:
"Arguments validation failed" error
"Arguments validation failed" error
CrewAI may pass tool arguments in different formats. Make the tool handle both: