alibaba/spring-ai-alibaba · error · IllegalArgumentException
Tool Calls Invalid input data:
Error message
Tool Calls Invalid input data:
What it means
Thrown by the tool-call input validator in PromptRunServiceImpl when the JSON Schema (draft-07) validation of the tool's input arguments fails. The message lists the specific ValidationMessage(s) produced by networknt json-schema-validator. It indicates the arguments the model/caller supplied do not conform to the tool's declared input schema.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/PromptRunServiceImpl.java:249
private final String inputSchema;
public MockFunction(String output, String inputSchema) {
this.output = output;
this.inputSchema = inputSchema;
}
@Override
public String apply(Map<String, Object> inputMap) {
try {
JsonNode schemaNode = objectMapper.readTree(inputSchema);
JsonNode dataNode = objectMapper.valueToTree(inputMap);
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
JsonSchema schema = factory.getSchema(schemaNode);
Set<ValidationMessage> errors = schema.validate(dataNode);
if (!errors.isEmpty()) {
throw new IllegalArgumentException("Tool Calls Invalid input data: " + errors);
}
return this.output;
} catch (JsonProcessingException e) {
log.error("JSON 处理失败: ", e);
throw new RuntimeException("JSON processing failed: " + e.getMessage(), e);
} catch (Exception e) {
log.error("JSON 处理失败: ", e);
throw new RuntimeException("Schema validation failed: " + e.getMessage(), e);
}
}
}
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Read the ValidationMessage details appended after the prefix — they name the JSON path and the violated keyword.
- Fix the caller so the input JSON matches the tool's inputSchema (required fields, types).
- If the model generated bad arguments, tighten the schema description/examples so the LLM produces conforming input.
- If the schema itself is wrong, correct the tool definition's schema before re-running.
Example fix
// before (missing required field)
{"city": "Hangzhou"}
// after (schema requires city + unit)
{"city": "Hangzhou", "unit": "celsius"} Defensive patterns
Strategy: validation
Validate before calling
JsonNode data = mapper.readTree(inputJson); Set<ValidationMessage> errs = factory.getSchema(schemaNode).validate(data); if (!errs.isEmpty()) throw new IllegalArgumentException(errs.toString());
Type guard
boolean isValidInput(JsonNode data, JsonNode schema) {
return data != null && schema != null &&
schemaFactory.getSchema(schema).validate(data).isEmpty();
} Try / catch
try {
schema.validate(dataNode);
} catch (IllegalArgumentException e) {
log.warn("Tool input failed schema validation: {}", e.getMessage());
// return 400 with the validation messages
} Prevention
- Keep tool inputSchema and its description in sync so the LLM emits conforming arguments
- Unit-test tools with schema validation against sample inputs
- Log the full ValidationMessage set, not just the prefix
- Use strict schema mode and required fields to catch drift early
When it happens
Trigger: Prompt/tool run where the parsed input dataNode violates the schema: missing required properties, wrong types, unmet enum/const values, or additionalProperties violations detected by schema.validate(dataNode).
Common situations: LLM generated arguments that don't match the declared tool schema; prompt definition edited so the schema changed but callers still send the old shape; caller passing a JSON array where object expected; numeric string where integer declared.
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/834a95acda984188.
Report an issue: GitHub.