From 1a931910ceeaf318f962568f8b7dce765bd7a646 Mon Sep 17 00:00:00 2001 From: wyp <17371270989@163.com> Date: Tue, 21 Jul 2026 14:27:11 +0800 Subject: [PATCH] fix(core): guard null/blank input in ToolValidator.validateInput MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a ToolUseBlock has parsed arguments in its `input` map but no raw `content` string, `ToolExecutor.executeCore` passes `null` to `ToolValidator.validateInput()`, which forwards it to networknt-schema's `validate(null, …)`. networknt-schema then throws NullPointerException: argument "content" is null Treat null/blank input as `"{}"` before validation so that optional-field schemas pass cleanly and required-field schemas still surface the expected validation errors. Co-Authored-By: Claude Opus 4.6 --- .../main/java/io/agentscope/core/tool/ToolValidator.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/agentscope-core/src/main/java/io/agentscope/core/tool/ToolValidator.java b/agentscope-core/src/main/java/io/agentscope/core/tool/ToolValidator.java index 8f0d0fe818..c997becaac 100644 --- a/agentscope-core/src/main/java/io/agentscope/core/tool/ToolValidator.java +++ b/agentscope-core/src/main/java/io/agentscope/core/tool/ToolValidator.java @@ -79,6 +79,13 @@ public static String validateInput(String input, Map schema) { return null; // No schema, validation passes } + // Defensive: treat null/blank input as empty JSON object so that + // networknt-schema does not throw NPE ("argument 'content' is null") + // when a ToolUseBlock carries parsed arguments but no raw content string. + if (input == null || input.isBlank()) { + input = "{}"; + } + try { // Convert schema to JSON string String schemaJson = JsonUtils.getJsonCodec().toJson(schema);