alibaba/spring-ai-alibaba · error · BizException

BUILD_TOOL_RESULT_ERROR

BUILD_TOOL_RESULT_ERROR

Error message

BUILD_TOOL_RESULT_ERROR

What it means

BUILD_TOOL_RESULT_ERROR is thrown by buildOutputs in ToolExecutionServiceImpl when constructing the tool's output map from the parsed response JSON object fails. The try block assigns respJSONObj to outputs (the per-field constructOutputs step is currently commented out), so in practice this fires only on truly unexpected runtime failures during output assembly.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/ToolExecutionServiceImpl.java:291

			}
		}
	}

	/**
	 * Builds the output map from the API response.
	 * @param respJSONObj The JSON response object
	 * @param outputParams The expected output parameters
	 * @return Map containing the processed output values
	 */
	public Map<String, Object> buildOutputs(Map<String, Object> respJSONObj, List<ApiParameter> outputParams) {
		Map<String, Object> outputs = new HashMap<String, Object>();

		try {
			outputs = respJSONObj;
			// constructOutputs(respJSONObj, outputs, outputParams);
		}
		catch (Exception e) {
			throw new BizException(ErrorCode.BUILD_TOOL_RESULT_ERROR.toError(), e);
		}

		return outputs;
	}

	/**
	 * Recursively constructs output objects based on parameter types. Handles different
	 * data types including objects and arrays.
	 * @param sourceObject The source data object
	 * @param targetObj The target object to populate
	 * @param outputParams The output parameter definitions
	 */
	private void constructOutputs(Map<String, Object> sourceObject, Map<String, Object> targetObj,
			List<ApiParameter> outputParams) {
		if (CollectionUtils.isEmpty(outputParams)) {
			return;
		}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Inspect the cause attached to the BizException for the real failure.
  2. Log and verify the raw response JSON the remote tool returned before output building.
  3. If you modified constructOutputs, review it for null/shape assumptions and re-run.
  4. Check the remote tool's API contract and normalize its response before calling buildOutputs.

Example fix

// before
Object outputs = buildOutputs(respJSONObj, outputParams); // throws BUILD_TOOL_RESULT_ERROR
// after
try {
    Object outputs = buildOutputs(respJSONObj, outputParams);
} catch (BizException e) {
    log.warn("Failed to build tool result", e.getCause());
    Object outputs = Collections.emptyMap(); // graceful degradation
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (respJSONObj == null) { log.warn("Tool returned null response; skipping output build"); return Collections.emptyMap(); }

Type guard

if (!(resp instanceof JSONObject)) { throw new IllegalStateException("Unexpected response type: " + resp.getClass()); }

Try / catch

try { outputs = buildOutputs(resp, outputParams); } catch (BizException e) { log.error("BUILD_TOOL_RESULT_ERROR", e.getCause()); outputs = Collections.emptyMap(); }

Prevention

When it happens

Trigger: buildOutputs receiving a respJSONObj that causes a RuntimeException during assignment/output-map construction; any future re-enabled constructOutputs logic failing on unexpected response shapes.

Common situations: Remote tool API returning null or an unexpected structure that downstream output building cannot handle; regression after modifying buildOutputs/constructOutputs; memory/runtime errors during large response handling.

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/6be4266666a6ec25. Report an issue: GitHub.