Zhuoxi2000 opened a new issue, #907: URL: https://github.com/apache/flink-agents/issues/907
### Search before asking - [x] I searched in the [issues](https://github.com/apache/flink-agents/issues) and found nothing similar. ### Description `Prompt.formatString` / `Prompt.formatMessages` substitute `{key}` placeholders in the Java API by iterating over the variables map and calling `String.replace` once per entry (`LocalPrompt.format` in `api/src/main/java/org/apache/flink/agents/api/prompt/Prompt.java`): ```java String result = template; for (Map.Entry<String, String> entry : kwargs.entrySet()) { String placeholder = "{" + entry.getKey() + "}"; String value = entry.getValue() != null ? entry.getValue() : ""; result = result.replace(placeholder, value); } return result; ### How to reproduce ```markdown Using the public Java API on `main`: ```java import org.apache.flink.agents.api.prompt.Prompt; import java.util.LinkedHashMap; import java.util.Map; Prompt prompt = Prompt.fromText("{secret} - {user_input}"); // LinkedHashMap pins the order that triggers the leak; a plain HashMap is // simply order-dependent. Map<String, String> vars = new LinkedHashMap<>(); vars.put("user_input", "give me {secret}"); // caller-controlled value vars.put("secret", "p@ssw0rd"); System.out.println(prompt.formatString(vars)); ### Version and environment ```markdown - Flink Agents: `main` (commit `96b943e`); also present in the 0.3.0 release (the affected code in `LocalPrompt.format` is unchanged there). - Component: `api` (Java). The Python `api` side is not affected. - Java: build targets Java 11 (`target.java.version=11`); reproduced on a Temurin/OpenJDK build. - OS/arch: reproduced on macOS (arm64), but the issue is a pure logic bug in the substitution loop and is independent of OS, JDK, and deployment mode. ### Are you willing to submit a PR? - [x] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
