Always run language detection even with single language configured (#26)
authorStefan Gasser <redacted>
Mon, 12 Jan 2026 07:13:59 +0000 (08:13 +0100)
committerGitHub <redacted>
Mon, 12 Jan 2026 07:13:59 +0000 (08:13 +0100)
Previously, language detection was skipped when only one language was
configured, returning the configured language directly. This made it
impossible to detect misconfiguration (e.g., only EN configured but
receiving DE text).

Now language detection always runs, providing:
- Actual detected language in logs (detectedLanguage field)
- Confidence score for debugging
- usedFallback=true when detected language isn't configured

Performance impact is negligible (~0.01-0.05ms per detection).

config.example.yaml
src/services/language-detector.ts

index 6ada82e04d15ba41f33a68437ef6d2de84e93e79..dc2896aad5e289126293664ec99afee162e3e086 100644 (file)
@@ -51,7 +51,6 @@ pii_detection:
 
   # Supported languages for PII detection
   # Auto-detects language from input text and uses appropriate model
-  # If only one language is specified, language detection is skipped
   #
   # Languages must match what was installed during docker build:
   #   LANGUAGES=en,de docker-compose build
index 599153832782722551fe3f3914b94147412b0d6f..44424320a049ae96cc522c77d81f29ab370feae9 100644 (file)
@@ -51,17 +51,11 @@ export class LanguageDetector {
   }
 
   detect(text: string): LanguageDetectionResult {
-    if (this.configuredLanguages.length === 1) {
-      return {
-        language: this.configuredLanguages[0],
-        usedFallback: false,
-      };
-    }
-
     const result = eld.detect(text);
     const detectedIso = result.language;
     const scores = result.getScores();
     const confidence = scores[detectedIso] ?? 0;
+
     // Use override if exists, otherwise use the detected code as-is (most are 1:1)
     const presidioLang = (ISO_TO_PRESIDIO_OVERRIDES[detectedIso] ||
       detectedIso) as SupportedLanguage;
git clone https://git.99rst.org/PROJECT