alibaba/spring-ai-alibaba · error · IllegalArgumentException
No default detector for PII type: ${type}
Error message
No default detector for PII type: ${type} What it means
PIIDetectionHook.getDefaultDetector() maps each supported PIIType to a built-in detector (email, phone, IP, MAC, URL, etc.). If a PIIType enum value has no default detector registered, the constructor fails fast with IllegalArgumentException rather than building a hook that can never match anything.
Source
Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/hook/pii/PIIDetectionHook.java:307
private String hashValue(String value) {
int hash = value.hashCode();
return String.format("<%s_hash:%08x>", piiType.name().toLowerCase(), hash);
}
private PIIDetector getDefaultDetector(PIIType type) {
switch (type) {
case EMAIL:
return PIIDetectors.emailDetector();
case CREDIT_CARD:
return PIIDetectors.creditCardDetector();
case IP:
return PIIDetectors.ipDetector();
case MAC_ADDRESS:
return PIIDetectors.macAddressDetector();
case URL:
return PIIDetectors.urlDetector();
default:
throw new IllegalArgumentException("No default detector for PII type: " + type);
}
}
@Override
public String getName() {
return "PIIDetection[" + piiType.name() + "]";
}
@Override
public List<JumpTo> canJumpTo() {
return List.of();
}
private static class ProcessResult {
final String redactedText;
final boolean hasMatches;
final List<PIIMatch> matches;
View on GitHub (pinned to f82da0b50f)
Solutions
- Use a PIIType with a built-in default detector (EMAIL, PHONE, IP, MAC_ADDRESS, URL, etc.).
- Register/override a custom detector for the unsupported type via the hook builder instead of relying on defaults.
- Upgrade or align the library version so the enum and detector implementations match.
Example fix
// before PIIDetectionHook hook = PIIDetectionHook.builder().piiType(PIIType.CUSTOM_TOKEN).build(); // no default // after PIIDetectionHook hook = PIIDetectionHook.builder().piiType(PIIType.EMAIL).build();
Defensive patterns
Strategy: validation
Validate before calling
Set<PIIType> supported = Set.of(PIIType.EMAIL, PIIType.PHONE, PIIType.IP, PIIType.MAC_ADDRESS, PIIType.URL);
if (!supported.contains(piiType)) {
throw new IllegalArgumentException(piiType + " has no default detector; register a custom one");
} Try / catch
try {
hook = PIIDetectionHook.builder().piiType(piiType).build();
} catch (IllegalArgumentException e) {
// fall back to a supported type or register custom detector
} Prevention
- Pin library versions so PIIType enum and detectors match
- Check release notes when new PIIType constants appear
- Register custom detectors for any non-default types
When it happens
Trigger: Constructing PIIDetectionHook (directly or via builder) with a PIIType value not covered by the default detector switch, or passing null/unknown type; typically after adding a new enum constant to PIIType without a detector.
Common situations: Using a newly added PIIType constant from a newer library version with an older hook implementation; providing a custom detector registry that omits a type; typos resolved to an unexpected enum member.
Related errors
- 参数 ${parameterName} 的值 ${value} 无法转换为类型 ${type}
- maxConcurrency must be at least 1, but got:
- Detected %d instance(s) of %s in text content
- piiType must be specified
- SkillRegistry cannot be null
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/e075e6d29aa01cdc.
Report an issue: GitHub.