You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Prompt placeholder substitution re-expands substituted values and is order-dependent #907
I searched in the 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):
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 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
Activity
wenjin272 commentedon Jul 15, 2026
Thanks for reporting this. I confirmed the issue on the current main branch. Since the Java implementation applies
String.replacesequentially, 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
formatStringandformatMessages.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.
Zhuoxi2000 commentedon Jul 15, 2026
Thanks for confirming and the assignment. added regression coverage for both paths as you suggested
[api][java] Substitute prompt placeholders in a single pass
[api][java] Substitute prompt placeholders in a single pass