-
Notifications
You must be signed in to change notification settings - Fork 14
feat: apply direct identifier replacements before rewrite LLM call #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
asteier2026
wants to merge
11
commits into
main
from
asteier2026/feature/rewrite-programmatic-prereplace
Closed
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9703dda
feat: apply direct identifier replacements before rewrite LLM call
asteier2026 2f35a4b
fix: use single-pass regex to prevent cascade replacements
asteier2026 0da33e3
fix: parse sensitivity disposition only once in _get_replace_pairs
asteier2026 c439bb2
fix: fall back to whitespace-normalized match in _get_replace_pairs
asteier2026 48f897f
fix: catch exceptions in _apply_direct_replacements and fall back gra…
asteier2026 dead64e
fix: normalize Unicode whitespace when filtering replacement map entries
asteier2026 2794d19
fix:raise error if no replace
asteier2026 b3d72c3
fix: raise in _apply_direct_replacements when replace entities are un…
asteier2026 998117d
fix: span-aware prereplace, tag-boundary tagged-text replacement, saf…
asteier2026 f7a43fc
fix: single-pass tagged text replacement to prevent cascade
asteier2026 005ceb2
style: apply ruff format to rewrite_generation.py and llm_replace_wor…
asteier2026 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_apply_tagged_text_replacementscan still cascadeThe function iterates over
pairssequentially, so a synthetic value that matches another entity's original is re-replaced in a later iteration. For example, withAlice → "Bob"andBob → "Carlos", iteration 1 rewrites[[Alice|first_name]]to[[Bob|first_name]], and iteration 2 then matches the freshly written[[Bob|first_name]]and replaces it with[[Carlos|first_name]]— Alice ends up as Carlos inCOL_PREREPLACE_TAGGED_TEXTwhile plain text correctly has "Bob". The LLM then sees wrong synthetic values in the tagged text it is asked to rewrite.The existing cascade test (
test_apply_direct_replacements_no_cascade_when_synthetic_matches_another_original) passes silently becauseCOL_TAGGED_TEXTis set to"Alice and Bob met."(plain, untagged text). The xml-mode regex(<first_name>)Alice(</first_name>)finds no matches in that string, so_apply_tagged_text_replacementsmakes no substitutions and the cascade is never exercised. There is also no assertion onCOL_PREREPLACE_TAGGED_TEXTin that test.The plain-text path uses a single-pass regex (
re.compile("|".join(...)).sub(...)) to avoid this exact problem. The tagged-text path needs the same treatment — build a single combined regex per notation format that matches all tagged originals simultaneously, then look up the replacement in one pass.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just fixed this too