MiddlewareError, which extends Error. Each error class has a unique code string and structured fields for programmatic handling.
Error Hierarchy
Catching Errors
Error Reference
ProhibitedPracticeError
Thrown when input matches an EU AI Act Article 5 prohibited practice (138 patterns, 8 categories, 6 languages).| Field | Type | Description |
|---|---|---|
code | 'PROHIBITED_PRACTICE' | Error code |
obligationId | string | EU AI Act obligation ID |
article | string | Article reference (e.g., 'Art.5') |
category | string | Prohibition category (e.g., 'social_scoring', 'subliminal') |
matchedPattern | string | The pattern that matched |
penalty | string | Maximum penalty (default: '€35M or 7% global turnover') |
PIIDetectedError
Thrown inblock sanitize mode when PII is detected in input.
| Field | Type | Description |
|---|---|---|
code | 'PII_DETECTED' | Error code |
piiType | string | PII type ID (e.g., 'SSN', 'IBAN', 'EMAIL') |
category | string | PII category (e.g., 'identity_national', 'financial') |
article | string | Legal basis (e.g., 'GDPR Art.87', 'GDPR Art.6') |
BiasDetectedError
Thrown inblock bias mode when aggregate bias score exceeds threshold.
| Field | Type | Description |
|---|---|---|
code | 'BIAS_DETECTED' | Error code |
findings | BiasEvidence[] | Array of individual findings |
totalScore | number | Aggregate weighted score |
threshold | number | Active threshold (domain-specific) |
domain | string | Active domain profile |
BiasEvidence:
| Field | Type | Description |
|---|---|---|
characteristic | string | Protected characteristic (e.g., 'sex', 'race') |
severity | string | 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL' |
evidence | string | Matched text |
score | number | Individual pattern score |
SafetyViolationError
Thrown when response safety score exceeds threshold.| Field | Type | Description |
|---|---|---|
code | 'SAFETY_VIOLATION' | Error code |
findings | SafetyFinding[] | Array of safety findings |
totalScore | number | Aggregate safety score |
threshold | number | Active threshold |
SafetyFinding:
| Field | Type | Description |
|---|---|---|
category | string | 'violence' | 'self_harm' | 'illegal_instructions' | 'pii_leakage' | 'hallucination_indicator' |
severity | string | 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL' |
evidence | string | Matched text |
score | number | Individual pattern score |
DisclosureMissingError
Thrown inblock disclosure mode when AI disclosure is not found in the response.
| Field | Type | Description |
|---|---|---|
code | 'DISCLOSURE_MISSING' | Error code |
language | string | Language checked |
expectedPatterns | string[] | Patterns that were expected |
HumanGateDeniedError
Thrown when HITL gate denies an action (human denial or timeout).| Field | Type | Description |
|---|---|---|
code | 'HUMAN_GATE_DENIED' | Error code |
reason | 'denied' | 'timeout' | Denial reason |
rule | string | Rule ID that triggered the gate |
timeoutMs | number | undefined | Timeout duration (only for timeout) |
DomainViolationError
Thrown by domain-specific hooks (HR, finance, healthcare, etc.).| Field | Type | Description |
|---|---|---|
code | 'DOMAIN_VIOLATION' | Error code |
domain | string | Domain that triggered the violation |
obligationId | string | Related obligation ID |
PermissionDeniedError
Thrown in agent mode when a method is on the passport’s denied list.| Field | Type | Description |
|---|---|---|
code | 'PERMISSION_DENIED' | Error code |
method | string | Denied method name |
BudgetExceededError
Thrown in agent mode when accumulated cost exceeds the session budget.| Field | Type | Description |
|---|---|---|
code | 'BUDGET_EXCEEDED' | Error code |
totalCost | number | Total accumulated cost (USD) |
limitUsd | number | Budget limit (USD) |
RateLimitError
Thrown in agent mode when actions exceed the per-minute rate limit.| Field | Type | Description |
|---|---|---|
code | 'RATE_LIMIT' | Error code |
maxPerMinute | number | Configured rate limit |
CircuitBreakerError
Thrown in agent mode when the circuit breaker is open (too many consecutive errors).| Field | Type | Description |
|---|---|---|
code | 'CIRCUIT_BREAKER' | Error code |
circuitState | string | Current state ('open' | 'half-open') |
errorThreshold | number | Error count that triggered the trip |
Configuration
Set modes and thresholds for each hook.
Agent Mode
Permission, budget, rate limit, circuit breaker.