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

  1. Use a PIIType with a built-in default detector (EMAIL, PHONE, IP, MAC_ADDRESS, URL, etc.).
  2. Register/override a custom detector for the unsupported type via the hook builder instead of relying on defaults.
  3. 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

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


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/e075e6d29aa01cdc. Report an issue: GitHub.