From 6503e1271c466da9d71389046849bd7ceed16b03 Mon Sep 17 00:00:00 2001 From: Ziyang Guo <121015044+RerankerGuo@users.noreply.github.com> Date: Thu, 6 Aug 2026 16:22:59 +0800 Subject: [PATCH] fix(prompt): default omitted conditional flags to false (#424) Always apply conditional-line filtering so tagged prompt lines are removed unless the corresponding boolean flag is explicitly true. Add regressions for omitted flags with and without format variables. Test: pytest tests/unit/test_prompt_handler.py -q --- reme/components/prompt_handler.py | 3 +-- tests/unit/test_prompt_handler.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/reme/components/prompt_handler.py b/reme/components/prompt_handler.py index 5c1a3a94..8a74a652 100644 --- a/reme/components/prompt_handler.py +++ b/reme/components/prompt_handler.py @@ -116,8 +116,7 @@ class PromptHandler: flags = {k: v for k, v in kwargs.items() if isinstance(v, bool)} formats = {k: v for k, v in kwargs.items() if not isinstance(v, bool)} - if flags: - prompt = self._apply_flag_filter(prompt, flags) + prompt = self._apply_flag_filter(prompt, flags) return prompt.format(**formats).strip() if formats else prompt diff --git a/tests/unit/test_prompt_handler.py b/tests/unit/test_prompt_handler.py index 2678d7dc..a07cd2c6 100644 --- a/tests/unit/test_prompt_handler.py +++ b/tests/unit/test_prompt_handler.py @@ -182,13 +182,18 @@ def test_flag_filter_removes_non_matching(): def test_flag_filter_default_false(): ph = PromptHandler() ph.load_prompt_dict({"p": "[debug] debug info\nbase"}) - # When no flags are passed at all, _apply_flag_filter is not called, - # so flagged lines are kept as-is (including the tag text after regex sub). - result = ph.prompt_format("p", debug=False) + result = ph.prompt_format("p") assert "debug info" not in result assert "base" in result +def test_flag_filter_defaults_false_with_format_variables(): + ph = PromptHandler() + ph.load_prompt_dict({"p": "[debug] debug {name}\nhello {name}"}) + result = ph.prompt_format("p", name="Alice") + assert result == "hello Alice" + + def test_flag_filter_unflagged_lines_always_kept(): ph = PromptHandler() ph.load_prompt_dict({"p": "line1\nline2\nline3"})