{"record":{"id":"834a95acda984188","repo":"alibaba/spring-ai-alibaba","slug":"tool-calls-invalid-input-data","errorCode":null,"errorMessage":"Tool Calls Invalid input data: ","messagePattern":"Tool Calls Invalid input data: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/PromptRunServiceImpl.java","lineNumber":249,"sourceCode":"        private final String inputSchema;\n        \n        public MockFunction(String output, String inputSchema) {\n            this.output = output;\n            this.inputSchema = inputSchema;\n        }\n        \n        @Override\n        public String apply(Map<String, Object> inputMap) {\n            try {\n                JsonNode schemaNode = objectMapper.readTree(inputSchema);\n                JsonNode dataNode = objectMapper.valueToTree(inputMap);\n                \n                JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);\n                JsonSchema schema = factory.getSchema(schemaNode);\n                Set<ValidationMessage> errors = schema.validate(dataNode);\n                \n                if (!errors.isEmpty()) {\n                    throw new IllegalArgumentException(\"Tool Calls Invalid input data: \" + errors);\n                }\n                return this.output;\n                \n            } catch (JsonProcessingException e) {\n                log.error(\"JSON 处理失败: \", e);\n                throw new RuntimeException(\"JSON processing failed: \" + e.getMessage(), e);\n            } catch (Exception e) {\n                log.error(\"JSON 处理失败: \", e);\n                throw new RuntimeException(\"Schema validation failed: \" + e.getMessage(), e);\n            }\n        }\n        \n    }\n    \n}\n","sourceCodeStart":231,"sourceCodeEnd":265,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/PromptRunServiceImpl.java#L231-L265","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before (missing required field)\n{\"city\": \"Hangzhou\"}\n// after (schema requires city + unit)\n{\"city\": \"Hangzhou\", \"unit\": \"celsius\"}","handlingStrategy":"validation","validationCode":"JsonNode data = mapper.readTree(inputJson);\nSet<ValidationMessage> errs = factory.getSchema(schemaNode).validate(data);\nif (!errs.isEmpty()) throw new IllegalArgumentException(errs.toString());","typeGuard":"boolean isValidInput(JsonNode data, JsonNode schema) {\n    return data != null && schema != null &&\n        schemaFactory.getSchema(schema).validate(data).isEmpty();\n}","tryCatchPattern":"try {\n    schema.validate(dataNode);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Tool input failed schema validation: {}\", e.getMessage());\n    // return 400 with the validation messages\n}","preventionTips":["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"],"tags":["json-schema","validation","tool-calls","input"],"backgroundTag":"schema-validation-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}