{"record":{"id":"62e954e64d0218f0","repo":"alibaba/spring-ai-alibaba","slug":"json-processing-failed","errorCode":null,"errorMessage":"JSON processing failed: ","messagePattern":"JSON processing 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":255,"sourceCode":"        \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":237,"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#L237-L265","documentation":"Wraps a Jackson JsonProcessingException thrown while parsing the tool input or schema JSON in the tool-call validator in PromptRunServiceImpl. It means the input arguments (or the schema itself) are not syntactically valid JSON, so validation never ran.","triggerScenarios":"apply() calls the JSON parser (ObjectMapper readTree or similar) on the tool input string or schema node and Jackson fails to parse malformed input.","commonSituations":"LLM emitted truncated/quoted-escaped JSON in the tool call; template variable substitution injected raw text into the JSON; invisible characters or single quotes used instead of double quotes.","solutions":["Inspect the nested JsonProcessingException message — Jackson reports line/column and the offending token.","Print/log the raw input string before parsing and validate it with a JSON linter.","Ensure the caller passes a parsed JSON object or a syntactically valid JSON string.","If template substitution builds the JSON, escape values or build the tree with ObjectMapper instead of string concatenation."],"exampleFix":"// before: string-concatenated JSON\nString json = \"{\\\"q\\\": \" + userInput + \"}\";\n// after: build with Jackson\nObjectNode node = mapper.createObjectNode();\nnode.put(\"q\", userInput);","handlingStrategy":"validation","validationCode":"try { mapper.readTree(inputJson); } catch (JsonProcessingException e) { /* invalid JSON */ }","typeGuard":"boolean isJsonParsable(String s) {\n    try { mapper.readTree(s); return true; }\n    catch (JsonProcessingException e) { return false; }\n}","tryCatchPattern":"catch (JsonProcessingException e) {\n    log.error(\"Invalid JSON in tool input at {}:{}\", e.getLocation() != null ? e.getLocation().getLineNr() : -1, e.getLocation() != null ? e.getLocation().getColumnNr() : -1, e);\n    throw new RuntimeException(\"JSON processing failed: \" + e.getMessage(), e);\n}","preventionTips":["Never build JSON by string concatenation; use ObjectMapper/ObjectNode","Validate LLM tool-call arguments are parseable before validation","Strip markdown fences/code-block wrappers from model output before parsing","Log the raw input string on parse failure"],"tags":["json","jackson","parse-error","tool-calls"],"backgroundTag":"json-parse-error","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"}