How to Enable PII Redaction in OmniRoute: A Complete Configuration Guide

Enable PII redaction in OmniRoute by setting the PII_REDACTION_ENABLED feature flag to true via environment variable, database record, or programmatic override.

OmniRoute protects sensitive user data through an opt-in PII redaction system that sanitizes personally identifiable information before it reaches downstream LLM providers. Because the system defaults to disabled for safety and performance, operators must explicitly enable PII redaction using the feature flag infrastructure built into the diegosouzapw/OmniRoute codebase. This guide explains the three-layer configuration hierarchy and provides concrete implementation examples drawn directly from the source.

Understanding the PII_REDACTION_ENABLED Feature Flag

OmniRoute implements PII protection as a boolean feature flag evaluated at runtime. The flag is defined in src/shared/constants/featureFlagDefinitions.ts (line 51) and defaults to false (disabled), requiring deliberate action to activate redaction capabilities across your deployment.

The Three-Layer Evaluation Hierarchy

The system checks for the flag value in descending order of precedence:

  1. Database Override — A record in the SQLite feature_flags table takes highest priority
  2. Environment Variable — If no database entry exists, the system reads process.env.PII_REDACTION_ENABLED
  3. Default Fallback — When neither source is present, the flag evaluates to false

This architecture allows emergency toggling via database updates without restarting services, while still supporting traditional environment-based configuration.

Methods to Enable PII Redaction

Option 1: Environment Variable (Quickest)

Set the flag before starting the Node.js process. This method applies immediately but requires a restart to change.


# Terminal export

export PII_REDACTION_ENABLED=true

# Or in your .env file

PII_REDACTION_ENABLED=true

In the source code, src/shared/utils/inputSanitizer.ts (lines 120-124) handles this via parseEnvBoolean(process.env.PII_REDACTION_ENABLED, false), ensuring string values like "true" are properly coerced to booleans.

Option 2: Database Feature Flag (Persistent)

For production deployments requiring dynamic toggling, insert or update the flag record in the SQLite database. This method persists across restarts and takes precedence over environment variables.

import { getDbInstance } from "@/src/lib/db/core";

const db = getDbInstance();
db.prepare(
  `INSERT INTO feature_flags (key, value) 
   VALUES (?, ?)
   ON CONFLICT(key) DO UPDATE SET value = excluded.value`
).run("PII_REDACTION_ENABLED", "true");

This approach stores the key "PII_REDACTION_ENABLED" with string value "true" in the feature_flags table, allowing administrators to enable redaction without touching server configuration or restarting containers.

Option 3: Programmatic Override (Testing)

Use the test helper setFeatureFlagOverride to temporarily flip the flag during unit tests or maintenance scripts. This affects only the current process context.

import { setFeatureFlagOverride } from "@/src/lib/guardrails/utils";

// Force enable for current process
setFeatureFlagOverride("PII_REDACTION_ENABLED", "true");

The test suite at tests/unit/piiSanitizer.test.ts demonstrates this pattern, while tests/unit/pii-opt-in-default.test.ts confirms that the flag defaults to off when no overrides are present.

How the Redaction Works Under the Hood

The PII Masker Guardrail

When enabled, the redaction logic executes in src/lib/guardrails/piiMasker.ts (lines 15-18). The guardrail calls isFeatureFlagEnabled("PII_REDACTION_ENABLED") before processing each request. If the function returns true, the payload routes through the sanitization pipeline; otherwise, data passes through unmodified.

Input Sanitization Flow

The actual detection and removal of PII fields occurs in src/shared/utils/inputSanitizer.ts. This module integrates with the feature flag system through the function isFeatureFlagEnabled, ensuring consistent evaluation across the codebase according to the repository source code.

Verification and Testing

Confirm your configuration is active using the utility function:

import { isFeatureFlagEnabled } from "@/src/lib/guardrails/utils";

if (isFeatureFlagEnabled("PII_REDACTION_ENABLED")) {
  console.log("PII redaction is active via database or environment setting");
}

For continuous integration pipelines, reference the existing test suites that validate both the default-off behavior in tests/unit/pii-opt-in-default.test.ts and the redaction logic when explicitly enabled.

Summary

  • PII redaction is opt-in and defaults to false in OmniRoute to prevent unintended data transformation.
  • Three configuration methods exist: environment variables (fastest), database records (persistent and override-capable), and programmatic overrides (testing only).
  • Key implementation files include src/lib/guardrails/piiMasker.ts for guardrail logic and src/shared/utils/inputSanitizer.ts for the sanitization engine.
  • Database entries take precedence over environment variables, enabling runtime toggling without deployments.

Frequently Asked Questions

Does OmniRoute redact PII by default?

No. According to the guardrail documentation and test suites in the diegosouzapw/OmniRoute repository, PII redaction is strictly opt-in. The PII_REDACTION_ENABLED flag defaults to false, meaning all requests pass through unmodified unless an administrator explicitly enables the feature via environment variable or database configuration.

Which configuration method takes priority if I set both an environment variable and a database flag?

The database feature flag takes precedence. OmniRoute evaluates the PII_REDACTION_ENABLED value in a three-layer hierarchy: first checking the SQLite feature_flags table, then falling back to process.env.PII_REDACTION_ENABLED, and finally defaulting to false. This design allows operators to override environment settings dynamically without restarting services.

What happens to detected PII when the flag is enabled?

When PII_REDACTION_ENABLED evaluates to true, the PII masker guardrail in src/lib/guardrails/piiMasker.ts routes the request payload through the input sanitizer. The sanitizer rewrites or removes detected personally identifiable information fields before forwarding the request to LLM providers, ensuring sensitive data never leaves your infrastructure in raw form.

Can I enable PII redaction for just one specific request or route?

Not directly through the feature flag system. The PII_REDACTION_ENABLED flag operates globally across the deployment. For request-specific handling, you would need to implement custom middleware that conditionally triggers the sanitization logic in src/shared/utils/inputSanitizer.ts rather than relying on the global guardrail mechanism.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →