alibaba/spring-ai-alibaba · error · RuntimeException

invalid output

Error message

invalid output

What it means

QuestionClassifierNodeSection.renderEdges generates an edge lambda that reads the classifier's output key and maps the classification id to the next node. If the value matches none of the known class ids, the generated code throws RuntimeException("invalid output") as a final fallback.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/service/generator/workflow/sections/QuestionClassifierNodeSection.java:68

				""", node.getId(), varName, ObjectToCodeUtil.toCode(nodeData.getChatModeName()),
				ObjectToCodeUtil.toCode(nodeData.getModeParams()), nodeData.getInputSelector().getNameInCode(),
				nodeData.getOutputKey(),
				ObjectToCodeUtil.toCode(nodeData.getClasses()
					.stream()
					.collect(Collectors.toUnmodifiableMap(QuestionClassifierNodeData.ClassConfig::id,
							QuestionClassifierNodeData.ClassConfig::classTemplate, (a, b) -> b))),
				ObjectToCodeUtil.toCode(List.of(nodeData.getPromptTemplate())));
	}

	@Override
	public String renderEdges(QuestionClassifierNodeData nodeData, List<Edge> edges) {
		Map<String, String> classIdToName = nodeData.getClassIdToName();
		// 规定edge的sourceHandle为caseId,前面的转化需要符合这条规则
		String edgeCode = String.format("""
				state -> {
				    String result = state.value("%s").orElseThrow().toString();
				    %s
				    throw new RuntimeException("invalid output");
				}
				""", nodeData.getOutputKey(),
				nodeData.getClasses()
					.stream()
					.map(QuestionClassifierNodeData.ClassConfig::id)
					.map(id -> String.format("""
							if("%s".equals(result)) {
							    return "%s";
							}
							""", id, classIdToName.getOrDefault(id, id)))
					.collect(Collectors.joining("\n")));

		Map<String, String> caseToTarget = edges.stream()
			.collect(Collectors.toUnmodifiableMap(
					e -> classIdToName.getOrDefault(e.getSourceHandle(), e.getSourceHandle()), Edge::getTarget));

		return String.format("""
				// render QuestionNode [%s]'s edge

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Verify the classifier classes' ids/labels match what the classification prompt produces
  2. Ensure outputKey is unique and written only by the classifier node
  3. Add a default/fallback class so every model response maps to a known id
  4. Check prompt template constraints so the model outputs exactly one class label

Example fix

// before
classes: [A, B] // model returns "C"
// after
classes: [A, B, {id:"other", label:"fallback"}]
Defensive patterns

Strategy: try-catch

Validate before calling

String out = state.value(outputKey).orElse(""); if (classes.stream().noneMatch(c -> c.id().equals(out))) { log.warn("Classifier output not a known class id: {}", out); }

Type guard

null

Try / catch

try { edgeFunction.apply(state); } catch (RuntimeException e) { routeToFallbackNode(state); }

Prevention

When it happens

Trigger: At runtime, state.value(outputKey) contains a string that is not one of the nodeData class ids — e.g., the classifier LLM returned text that mapped to an unexpected/normalized id, or outputKey was overwritten by another node.

Common situations: Classifier model output not matching any configured class label; class ids changed in the DSL after edges were generated; two nodes writing to the same output key; model returning empty/garbage classification.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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