refactor: migrate prompt .replace() chains to substitute_placeholders#89
Merged
lipikaramaswamy merged 2 commits intoApr 6, 2026
Merged
Conversation
lipikaramaswamy
approved these changes
Apr 3, 2026
Collaborator
lipikaramaswamy
left a comment
There was a problem hiding this comment.
All looks good, workflow ran e2e, just a few nits.
3a6b451 to
4b2f5da
Compare
…placeholders Extract render_template from rewrite/parsers.py into a shared engine/prompt_utils.py module, renamed to substitute_placeholders. The new function uses a single-pass regex to prevent cross-contamination when user-controlled text contains placeholder tokens. Strict mode (default) raises on malformed keys and unresolved placeholders, and warns on unused keys. Migrated all 12 prompt-building functions across detection, replace, and rewrite modules. Closes #66
Add inline comment documenting that _PLACEHOLDER_RE only matches [a-zA-Z0-9_] (no hyphens). Add two tests for repeated placeholders and empty replacement values.
4b2f5da to
b77af49
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
render_templatefromrewrite/parsers.pyinto a sharedengine/prompt_utils.pymodule, renamed tosubstitute_placeholders<<SCORE>>appearing in a replacement value won't be double-substituted)ValueErroron malformed keys and unresolved placeholders, and warns on unused keysdetection/,replace/, andrewrite/modulesCloses #66
Changes
engine/prompt_utils.py(new)substitute_placeholders()with strict/non-strict modestests/engine/test_prompt_utils.py(new)detection/detection_workflow.pyreplace/llm_replace_workflow.pyrewrite/domain_classification.py.replace()chain ->substitute_placeholders()rewrite/evaluate.pyrewrite/final_judge.pyrewrite/parsers.pyrender_templateand unusedimport rerewrite/qa_generation.pyrewrite/repair.pyrewrite/rewrite_generation.pyrewrite/sensitivity_disposition.py.replace()chain ->substitute_placeholders()tests/engine/test_parsers.pyrender_templatetests (moved to test_prompt_utils)Test plan
substitute_placeholderscovering basic substitution, cross-contamination prevention, strict mode validation, and non-strict fallbackruff formatandruff checkpass