You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Zhuoxi2000 (via GitHub)" <gi...@apache.org> on 2026/07/15 00:34:01 UTC
[I] [Bug] Prompt placeholder substitution re-expands substituted values and is order-dependent [flink-agents]
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: issues-unsubscribe@flink.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Prompt placeholder substitution re-expands substituted values and is order-dependent [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 closed issue #907: [Bug] Prompt placeholder substitution re-expands substituted values and is order-dependent
URL: https://github.com/apache/flink-agents/issues/907
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Prompt placeholder substitution re-expands substituted values and is order-dependent [flink-agents]
Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on issue #907:
URL: https://github.com/apache/flink-agents/issues/907#issuecomment-4976588853
Thanks for reporting this. I confirmed the issue on the current main branch. Since the Java implementation applies `String.replace` sequentially, placeholders introduced by an earlier substitution may be expanded by a later one, making the result dependent on the map iteration order. The native Python formatter performs a single-pass substitution and is not affected.
I think that the Java implementation should only scan placeholders from the original template, with regression coverage for both `formatString` and `formatMessages`.
Thanks for indicating that you’re willing to submit a PR, I’ve assigned the issue to you. Please let us know if you have any questions along the way.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Prompt placeholder substitution re-expands substituted values and is order-dependent [flink-agents]
Posted by "Zhuoxi2000 (via GitHub)" <gi...@apache.org>.
Zhuoxi2000 commented on issue #907:
URL: https://github.com/apache/flink-agents/issues/907#issuecomment-4976711558
> Thanks for reporting this. I confirmed the issue on the current main branch. Since the Java implementation applies `String.replace` sequentially, placeholders introduced by an earlier substitution may be expanded by a later one, making the result dependent on the map iteration order. The native Python formatter performs a single-pass substitution and is not affected.
>
> I think that the Java implementation should only scan placeholders from the original template, with regression coverage for both `formatString` and `formatMessages`.
>
> Thanks for indicating that you’re willing to submit a PR, I’ve assigned the issue to you. Please let us know if you have any questions along the way.
Thanks for confirming and the assignment. added regression coverage for both paths as you suggested
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org