Skip to content

Commit 12b1f24

Browse files
authored
escape tool name and description (#4747)
Signed-off-by: Jiaping Zeng <jpz@amazon.com>
1 parent 09da796 commit 12b1f24

File tree

1 file changed

+3
-2
lines changed
  • ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent

1 file changed

+3
-2
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import java.util.regex.Pattern;
6565
import java.util.stream.Collectors;
6666

67+
import org.apache.commons.text.StringEscapeUtils;
6768
import org.apache.commons.text.StringSubstitutor;
6869
import org.opensearch.ExceptionsHelper;
6970
import org.opensearch.OpenSearchException;
@@ -236,8 +237,8 @@ public static String addToolsToFunctionCalling(
236237
}
237238
Tool tool = tools.get(toolName);
238239
Map<String, Object> toolParams = new HashMap<>();
239-
toolParams.put(NAME, tool.getName());
240-
toolParams.put(DESCRIPTION, tool.getDescription());
240+
toolParams.put(NAME, StringEscapeUtils.escapeJson(tool.getName()));
241+
toolParams.put(DESCRIPTION, StringEscapeUtils.escapeJson(tool.getDescription()));
241242
Map<String, ?> attributes = tool.getAttributes();
242243
if (attributes != null) {
243244
for (String key : attributes.keySet()) {

0 commit comments

Comments
 (0)