Skip to main content
All SDK errors extend MiddlewareError, which extends Error. Each error class has a unique code string and structured fields for programmatic handling.

Error Hierarchy

Error
└── MiddlewareError (code: string)
    ├── ProhibitedPracticeError    PROHIBITED_PRACTICE
    ├── PIIDetectedError           PII_DETECTED
    ├── BiasDetectedError          BIAS_DETECTED
    ├── SafetyViolationError       SAFETY_VIOLATION
    ├── DisclosureMissingError     DISCLOSURE_MISSING
    ├── HumanGateDeniedError       HUMAN_GATE_DENIED
    ├── DomainViolationError       DOMAIN_VIOLATION
    ├── PermissionDeniedError      PERMISSION_DENIED
    ├── BudgetExceededError        BUDGET_EXCEEDED
    ├── RateLimitError             RATE_LIMIT
    └── CircuitBreakerError        CIRCUIT_BREAKER

Catching Errors

import {
  ProhibitedPracticeError,
  PIIDetectedError,
  BiasDetectedError,
  SafetyViolationError,
  HumanGateDeniedError,
  BudgetExceededError,
  MiddlewareError,
} from '@complior/sdk';

try {
  const response = await client.chat.completions.create({
    model: 'gpt-4',
    messages: [{ role: 'user', content: userInput }],
  });
} catch (error) {
  if (error instanceof ProhibitedPracticeError) {
    console.error(`Art.5 violation: ${error.category}`);
    console.error(`Penalty: ${error.penalty}`);
  } else if (error instanceof PIIDetectedError) {
    console.error(`PII found: ${error.piiType} (${error.category})`);
  } else if (error instanceof BiasDetectedError) {
    console.error(`Bias score: ${error.totalScore} > ${error.threshold}`);
    error.findings.forEach(f =>
      console.error(`  ${f.characteristic}: ${f.severity} (${f.score})`)
    );
  } else if (error instanceof HumanGateDeniedError) {
    console.error(`HITL ${error.reason}: rule "${error.rule}"`);
  } else if (error instanceof BudgetExceededError) {
    console.error(`$${error.totalCost} exceeds $${error.limitUsd} limit`);
  } else if (error instanceof MiddlewareError) {
    // Catch-all for any compliance error
    console.error(`Compliance error [${error.code}]: ${error.message}`);
  }
}

Error Reference

ProhibitedPracticeError

Thrown when input matches an EU AI Act Article 5 prohibited practice (138 patterns, 8 categories, 6 languages).
FieldTypeDescription
code'PROHIBITED_PRACTICE'Error code
obligationIdstringEU AI Act obligation ID
articlestringArticle reference (e.g., 'Art.5')
categorystringProhibition category (e.g., 'social_scoring', 'subliminal')
matchedPatternstringThe pattern that matched
penaltystringMaximum penalty (default: '€35M or 7% global turnover')

PIIDetectedError

Thrown in block sanitize mode when PII is detected in input.
FieldTypeDescription
code'PII_DETECTED'Error code
piiTypestringPII type ID (e.g., 'SSN', 'IBAN', 'EMAIL')
categorystringPII category (e.g., 'identity_national', 'financial')
articlestringLegal basis (e.g., 'GDPR Art.87', 'GDPR Art.6')

BiasDetectedError

Thrown in block bias mode when aggregate bias score exceeds threshold.
FieldTypeDescription
code'BIAS_DETECTED'Error code
findingsBiasEvidence[]Array of individual findings
totalScorenumberAggregate weighted score
thresholdnumberActive threshold (domain-specific)
domainstringActive domain profile
BiasEvidence:
FieldTypeDescription
characteristicstringProtected characteristic (e.g., 'sex', 'race')
severitystring'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
evidencestringMatched text
scorenumberIndividual pattern score

SafetyViolationError

Thrown when response safety score exceeds threshold.
FieldTypeDescription
code'SAFETY_VIOLATION'Error code
findingsSafetyFinding[]Array of safety findings
totalScorenumberAggregate safety score
thresholdnumberActive threshold
SafetyFinding:
FieldTypeDescription
categorystring'violence' | 'self_harm' | 'illegal_instructions' | 'pii_leakage' | 'hallucination_indicator'
severitystring'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
evidencestringMatched text
scorenumberIndividual pattern score

DisclosureMissingError

Thrown in block disclosure mode when AI disclosure is not found in the response.
FieldTypeDescription
code'DISCLOSURE_MISSING'Error code
languagestringLanguage checked
expectedPatternsstring[]Patterns that were expected

HumanGateDeniedError

Thrown when HITL gate denies an action (human denial or timeout).
FieldTypeDescription
code'HUMAN_GATE_DENIED'Error code
reason'denied' | 'timeout'Denial reason
rulestringRule ID that triggered the gate
timeoutMsnumber | undefinedTimeout duration (only for timeout)

DomainViolationError

Thrown by domain-specific hooks (HR, finance, healthcare, etc.).
FieldTypeDescription
code'DOMAIN_VIOLATION'Error code
domainstringDomain that triggered the violation
obligationIdstringRelated obligation ID

PermissionDeniedError

Thrown in agent mode when a method is on the passport’s denied list.
FieldTypeDescription
code'PERMISSION_DENIED'Error code
methodstringDenied method name

BudgetExceededError

Thrown in agent mode when accumulated cost exceeds the session budget.
FieldTypeDescription
code'BUDGET_EXCEEDED'Error code
totalCostnumberTotal accumulated cost (USD)
limitUsdnumberBudget limit (USD)

RateLimitError

Thrown in agent mode when actions exceed the per-minute rate limit.
FieldTypeDescription
code'RATE_LIMIT'Error code
maxPerMinutenumberConfigured rate limit

CircuitBreakerError

Thrown in agent mode when the circuit breaker is open (too many consecutive errors).
FieldTypeDescription
code'CIRCUIT_BREAKER'Error code
circuitStatestringCurrent state ('open' | 'half-open')
errorThresholdnumberError count that triggered the trip

Configuration

Set modes and thresholds for each hook.

Agent Mode

Permission, budget, rate limit, circuit breaker.