{"record":{"id":"7c0729308f36e549","repo":"spring-projects/spring-ai","slug":"failed-to-parse-tool-input-schema","errorCode":null,"errorMessage":"Failed to parse tool input schema: ","messagePattern":"Failed to parse tool input schema: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatModel.java","lineNumber":1308,"sourceCode":"\t\t\t\t.properties(propertiesBuilder.build());\n\n\t\t\t// Add required fields if present\n\t\t\tObject requiredObj = schemaMap.get(\"required\");\n\t\t\tif (requiredObj instanceof java.util.List) {\n\t\t\t\tjava.util.List<String> required = (java.util.List<String>) requiredObj;\n\t\t\t\tfor (String req : required) {\n\t\t\t\t\tinputSchemaBuilder.addRequired(req);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn Tool.builder()\n\t\t\t\t.name(toolDefinition.name())\n\t\t\t\t.description(toolDefinition.description())\n\t\t\t\t.inputSchema(inputSchemaBuilder.build())\n\t\t\t\t.build();\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to parse tool input schema: \" + toolDefinition.inputSchema(), e);\n\t\t}\n\t}\n\n\t/**\n\t * Converts a Spring AI {@link AnthropicWebSearchTool} to the Anthropic SDK's\n\t * {@link WebSearchTool20260209}.\n\t * @param webSearchTool the web search configuration\n\t * @return the SDK web search tool\n\t */\n\tprivate WebSearchTool20260209 toSdkWebSearchTool(AnthropicWebSearchTool webSearchTool) {\n\t\tWebSearchTool20260209.Builder sdkBuilder = WebSearchTool20260209.builder();\n\n\t\tif (webSearchTool.getAllowedDomains() != null) {\n\t\t\tsdkBuilder.allowedDomains(webSearchTool.getAllowedDomains());\n\t\t}\n\t\tif (webSearchTool.getBlockedDomains() != null) {\n\t\t\tsdkBuilder.blockedDomains(webSearchTool.getBlockedDomains());\n\t\t}","sourceCodeStart":1290,"sourceCodeEnd":1326,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatModel.java#L1290-L1326","documentation":"AnthropicChatModel converts a Spring AI ToolDefinition's inputSchema JSON string into the Anthropic SDK's InputSchema builder. If parsing/converting that JSON schema fails, the model rethrows a RuntimeException 'Failed to parse tool input schema: <schema>' with the cause, so the malformed schema is visible in the message.","triggerScenarios":"Registering a tool whose inputSchema() string is not valid JSON, is empty, or has a structure the converter rejects (wrong JSON types inside the schema) when the request is built.","commonSituations":"Hand-written tool schema strings with typos; schema built via string concatenation; a ToolDefinition from another module producing a non-JSON schema; classpath version mismatch of JSON libraries.","solutions":["Read the schema text in the exception message and validate it with a JSON/JSON-Schema validator","Build the schema with JsonSchemaGenerator or a typed Map serialized via Jackson instead of hand-written strings","Verify the JSON uses proper types ('type' is a string, 'properties' is an object)","Align Spring AI and JSON library versions on the classpath"],"exampleFix":"// before\nToolDefinition.builder().name(\"t\").inputSchema(\"{type: 'object'}\").build(); // invalid JSON\n// after\nToolDefinition.builder().name(\"t\")\n    .inputSchema(\"{\\\"type\\\":\\\"object\\\",\\\"properties\\\":{}}\").build();","handlingStrategy":"validation","validationCode":"try (Parser p = new JsonParser()) { p.parse(toolDefinition.inputSchema()); } // reject invalid JSON before registering","typeGuard":"boolean isValidJson(String s) { try { new ObjectMapper().readTree(s); return true; } catch (Exception e) { return false; } }","tryCatchPattern":"try { schema = buildAnthropicSchema(toolDefinition); }\ncatch (RuntimeException e) { throw new IllegalStateException(\"Bad inputSchema for tool \" + toolDefinition.name(), e); }","preventionTips":["Generate schemas with JsonSchemaGenerator rather than hand-writing them","Lint tool schemas with a JSON-Schema validator in tests","Check classpath for conflicting JSON library versions"],"tags":["anthropic","json-schema","tools","parse-error"],"backgroundTag":"json-parse-error","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}