RedaktAIDocs

Error Handling

How Rdakt AI handles detection failures and configuration errors

Rdakt AI is designed to be safe by default. When something goes wrong during detection or anonymization, the middleware's behavior is controlled by the error policy.

Error Policies

warn_and_forward (Default)

If detection or anonymization fails, the middleware:

  1. Logs the error
  2. Forwards the original, unanonymized request to the LLM
  3. Fires the on_error callback if configured

This is fail-open behavior. Your application continues working even if Rdakt AI encounters an unexpected issue.

on_error: warn_and_forward

block

If detection or anonymization fails, the middleware:

  1. Logs the error
  2. Raises the exception
  3. The request is not sent to the LLM

This is fail-closed behavior. Use this when data leakage is worse than downtime.

on_error: block

Audit Mode

Audit mode is a special mode where Rdakt AI detects PII but does not anonymize it:

mode: audit

In audit mode:

  • Detection runs normally
  • Entities are logged and callbacks fire
  • The original text is forwarded to the LLM unchanged
  • No deanonymization occurs on responses

Use audit mode to assess what PII your application sends to LLMs before enabling anonymization.

Error Callback

Handle errors programmatically with the on_error callback:

def handle_error(error: Exception, stage: str) -> None:
    print(f"Rdakt error in {stage}: {error}")
    # Log to your monitoring system

middleware = RdaktMiddleware(
    on_error=handle_error,
)

The stage parameter indicates where the error occurred (e.g., "detection", "anonymization").

What Can Go Wrong

ScenarioDefault behaviorWith block
Regex pattern failsForward unanonymizedRaise exception
NER model not installedForward unanonymizedRaise exception
Session store unreachableForward unanonymizedRaise exception
Invalid config valueRaise ValueError at initRaise ValueError at init

Configuration validation errors always raise immediately, regardless of error policy — they indicate a programmer mistake, not a runtime condition.

On this page