Commit fbd782f
committed
fix(e2e): enable profile-specific model configuration and LoRA PII for ai-gateway
This commit fixes PII detection test failures for both dynamic-config and ai-gateway
profiles by implementing profile-specific model configuration and switching ai-gateway
from ModernBERT to LoRA-based PII detection.
## Problem
The PII detection E2E test was hardcoding "model": "general-expert", which caused
different issues across profiles:
1. **Dynamic-config**: Using "general-expert" directly bypassed the decision engine,
resulting in decision="" (empty string), causing PII policy lookups to fail → 0% accuracy
2. **AI-gateway**: Using outdated ModernBERT PII model which wasn't detecting any PII
entities during requests → 0% accuracy
## Root Causes
**Dynamic-config failure**:
- When test uses model="general-expert" directly, semantic router treats it as a
specified model (reason_code="model_specified"), NOT triggering decision engine
- Without decision routing, no decision name is set (decision="")
- PII policy code requires a valid decision name to check policies
- Result: PII detection disabled, 0/100 tests passed
**AI-gateway failure**:
- Profile was using legacy ModernBERT PII model (models/pii_classifier_modernbert-base_presidio_token_model)
- ModernBERT classifier initialized but never actually called during requests
- No "PII token classification" logs or "Detected PII" messages in test runs
- LoRA PII model proven to work correctly in dynamic-config profile
- Result: No PII detection, 0/100 tests passed
## Solution
### 1. Make PII Test Model Name Configurable (e2e/testcases/pii_detection.go)
**Change**: Added E2E_TEST_MODEL environment variable support
```go
// Get model name from environment, default to "general-expert" for backward compatibility
modelName := os.Getenv("E2E_TEST_MODEL")
if modelName == "" {
modelName = "general-expert"
}
```
**Why**: Different profiles need different model names:
- **dynamic-config**: Needs "MoM" to trigger decision engine routing
- **ai-gateway**: Can use "general-expert" (already configured as direct model)
**Impact**: Enables per-profile model configuration without test code changes
### 2. Configure Dynamic-Config to Use MoM Model (e2e/profiles/dynamic-config/profile.go)
**Change**: Set environment variable in Setup() method
```go
// Configure PII test to use MoM model for decision-based routing
os.Setenv("E2E_TEST_MODEL", "MoM")
```
**Why**:
- "MoM" (Mixture of Models) triggers the decision engine
- Decision engine classifies request → matches decision → enables PII detection
- "general-expert" bypasses decision engine → no decision → PII detection fails
**Impact**: Dynamic-config now gets 100/100 PII tests passed (100% accuracy)
### 3. Switch AI-Gateway to LoRA PII Detection (e2e/profiles/ai-gateway/values.yaml)
**Change 1**: Updated pii_model configuration to use LoRA auto-detection
```yaml
pii_model:
model_id: "models/lora_pii_detector_bert-base-uncased_model"
model_type: "auto" # Enables LoRA auto-detection
threshold: 0.7
use_cpu: true
pii_mapping_path: "models/lora_pii_detector_bert-base-uncased_model/pii_type_mapping.json"
```
**Why**:
- ModernBERT PII model was not detecting any PII (0% accuracy)
- LoRA PII model proven to work (dynamic-config achieved 100% accuracy)
- model_type: "auto" enables automatic LoRA model detection
- Same model used across all profiles for consistency
**Change 2**: Added default_decision for fallback PII detection
```yaml
- name: default_decision
description: "Default catch-all decision - blocks all PII for safety"
priority: 0
plugins:
- type: "pii"
configuration:
enabled: true
pii_types_allowed: []
```
**Why**:
- PII policy code (src/semantic-router/pkg/utils/pii/policy.go) falls back to "default_decision"
- When decision name is empty or not found, policy.go tries default_decision
- Ensures PII detection is always enabled, even for unmatched requests
**Impact**: AI-gateway now gets 100/100 PII tests passed (100% accuracy)
## Testing
**Before Fix**:
- dynamic-config: 0/100 PII tests passed (0% accuracy)
- ai-gateway: 0/100 PII tests passed (0% accuracy)
**After Fix**:
- dynamic-config: 100/100 PII tests passed (100% accuracy) ✅
- ai-gateway: 100/100 PII tests passed (100% accuracy) ✅
**Test Commands**:
```bash
# Dynamic-config profile
make e2e-cleanup && make e2e-test E2E_PROFILE=dynamic-config E2E_VERBOSE=true E2E_KEEP_CLUSTER=true
# AI-gateway profile
make e2e-cleanup && make e2e-test E2E_PROFILE=ai-gateway E2E_VERBOSE=true E2E_KEEP_CLUSTER=true
```
## Files Changed
1. **e2e/testcases/pii_detection.go** (Lines 136-140)
- Added E2E_TEST_MODEL environment variable support
- Defaults to "general-expert" for backward compatibility
- Enables profile-specific model configuration
2. **e2e/profiles/dynamic-config/profile.go** (Lines 46-47)
- Sets E2E_TEST_MODEL=MoM in Setup()
- Forces decision-based routing for PII tests
- Ensures decision name is populated for PII policy checks
3. **e2e/profiles/ai-gateway/values.yaml** (Lines 413-432, 490-497)
- Added default_decision for PII policy fallback
- Switched pii_model from ModernBERT to LoRA auto-detection
- Aligned with dynamic-config's working configuration
## Why This Works
**Dynamic-config**:
1. Test uses model="MoM" (via E2E_TEST_MODEL env var)
2. Triggers decision engine → classifies to decision (e.g., "other_decision")
3. Decision has PII plugin enabled → PII detection runs
4. LoRA PII classifier detects entities → policy blocks request ✅
**AI-gateway**:
1. Test uses model="general-expert" (default, no env var set)
2. Routes to decision (either matched or falls back to default_decision)
3. Decision has PII plugin enabled → PII detection runs
4. LoRA PII classifier detects entities → policy blocks request ✅
Both profiles now use the same proven LoRA PII detection model with 100% accuracy.
Signed-off-by: Yossi Ovadia <[email protected]>1 parent f0d58dd commit fbd782f
File tree
3 files changed
+37
-5
lines changed- e2e
- profiles
- ai-gateway
- dynamic-config
- testcases
3 files changed
+37
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
| 410 | + | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
413 | 434 | | |
414 | 435 | | |
415 | 436 | | |
| |||
467 | 488 | | |
468 | 489 | | |
469 | 490 | | |
470 | | - | |
471 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
472 | 495 | | |
473 | 496 | | |
474 | | - | |
| 497 | + | |
475 | 498 | | |
476 | 499 | | |
477 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
136 | 142 | | |
137 | 143 | | |
138 | | - | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
| |||
0 commit comments