alibaba/spring-ai-alibaba · warning · IllegalArgumentException

Invalid data format

Error message

Invalid data format

What it means

Warning logged in RoutingNode.getDecisionWithRetry when an LLM routing decision parses successfully but contains at least one agent name that is not among the configured subagents (invalidAgents non-empty). The invalid names are recorded in lastInvalidDecision so the next retry can include corrective feedback.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/agent/BasicAgentExecutor.java:438

				switch (item.getType()) {
					case TEXT -> text = item.getText();
					case IMAGE -> {
						if (StringUtils.isNotBlank(item.getUrl())) {
							String contentType = FileUtils.getContentType(item.getUrl());
							MediaType mediaType = MediaType.parseMediaType(contentType);
							media.add(Media.builder().mimeType(mediaType).data(new URL(item.getUrl())).build());
						}
						else if (StringUtils.isNotBlank(item.getPath())) {
							String contentType = FileUtils.getContentType(item.getPath());
							MediaType mediaType = MediaType.parseMediaType(contentType);
							Resource resource = fileManager.loadFile(item.getPath());
							media.add(new Media(mediaType, resource));
						}
						else if (StringUtils.isNotBlank(item.getData())) {
							// format should be data:image/png;base64,iVBORw0KGgoSUhEUgAAA
							int semicolonIndex = item.getData().indexOf(';');
							if (semicolonIndex == -1) {
								throw new IllegalArgumentException("Invalid data format");
							}

							String mimeType = item.getData().substring(0, semicolonIndex);
							MediaType mediaType = MediaType.parseMediaType(mimeType);
							media.add(new Media(mediaType, new ByteArrayResource(item.getData().getBytes())));
						}
						else {
							throw new BizException(ErrorCode.INVALID_PARAMS.toError("content",
									"image content must be url or path or data"));
						}
					}
				}
			}
		}
		catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Make subagent names exactly match the names referenced in the routing instruction
  2. Filter/whitelist model output to known subagent names before validation
  3. Provide few-shot examples in the instruction showing only valid names
  4. Add a fallback agent for graceful degradation

Example fix

// before
.subAgents(List.of(codingAgent)) // prompt tells model to route to "coder"
// after
.subAgents(List.of(codingAgent)) // prompt now says: route to "codingAgent"
Defensive patterns

Strategy: validation

Validate before calling

List<String> validNames = subAgents.stream().map(Agent::name).toList();
Set<String> valid = new java.util.HashSet<>(validNames);
List<String> requested = decision.getAgentNames();
List<String> invalid = requested.stream().filter(n -> !valid.contains(n)).toList();
if (!invalid.isEmpty()) log.warn("Decision names not registered: {} valid={}", invalid, validNames);

Prevention

When it happens

Trigger: decision.getAgentNames() returns names that fail validation against subAgents.stream().map(Agent::name); logged per failed attempt from apply().

Common situations: Model hallucinating plausible-but-unregistered agent names; typos or casing differences between prompt and registered subagent names; renaming a subagent without updating routing instructions.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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