{"record":{"id":"10d671adc972bc7b","repo":"alibaba/spring-ai-alibaba","slug":"schema-validation-failed","errorCode":null,"errorMessage":"Schema validation failed: ","messagePattern":"Schema validation failed: ","errorType":"exception","errorClass":"RuntimeException","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":258,"sourceCode":"            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":240,"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#L240-L265","documentation":"Generic catch-all in the tool-call validator in PromptRunServiceImpl: any non-Jackson exception during schema setup or validation (e.g. invalid schema document, null nodes, factory errors) is wrapped as \"Schema validation failed\". Unlike error 490/491 this is not an input-data problem but a failure validating, often due to a malformed or unsupported schema.","triggerScenarios":"factory.getSchema(schemaNode) receives a schema that is not a valid JSON Schema draft-07 document (e.g. wrong top-level type, unsupported keywords), or dataNode/schemaNode is null, or any unexpected runtime exception occurs in the validation block.","commonSituations":"Tool schema authored by hand with a typo (e.g. \"type\": \"strng\"); schema stored as a string but passed unparsed; using draft-07 keywords invalid per VersionFlag.V7; null schema because configuration was not loaded.","solutions":["Inspect the wrapped cause (e.getCause()) — the generic message hides the real exception.","Validate the schema JSON itself with a draft-07 schema validator/linter.","Confirm the schema node is parsed (readTree) not a raw string and is non-null.","Pin the schema to SpecVersion.VersionFlag.V7-compatible keywords only."],"exampleFix":"// before: raw string passed as schema\nJsonSchema schema = factory.getSchema(rawSchemaString);\n// after: parse first\nJsonNode schemaNode = mapper.readTree(rawSchemaString);\nJsonSchema schema = factory.getSchema(schemaNode);","handlingStrategy":"try-catch","validationCode":"JsonNode schemaNode = mapper.readTree(schemaJson);\nif (!schemaNode.isObject() || schemaNode.path(\"type\").isMissingNode()) throw new IllegalStateException(\"Invalid schema document\");","typeGuard":null,"tryCatchPattern":"catch (Exception e) {\n    Throwable root = e;\n    while (root.getCause() != null) root = root.getCause();\n    log.error(\"Schema validation setup failed, root cause: {}\", root.getMessage(), root);\n    throw new RuntimeException(\"Schema validation failed: \" + e.getMessage(), e);\n}","preventionTips":["Lint tool schemas against JSON Schema draft-07 before storing them","Always unwrap and log the root cause of the generic catch","Parse schema strings into JsonNode before passing to JsonSchemaFactory","Pin schema documents to V7 keywords supported by VersionFlag.V7"],"tags":["json-schema","validation","runtime"],"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-14T05:17:10.506Z"}