Repository navigation
Keep source text from closing the <source> block in the prompt - #5
Merged
Merged
Conversation
render_sources() escaped the title and location but inserted the chunk text as is, so a document containing </source> or </sources> could end the block early and put the rest of the chunk outside the sources. Escape the < of any source/sources tag inside the text; the rest of the text is unchanged. Fixes #4
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.
What was wrong:
render_sources()in backend/src/docmind/rag/prompt.py HTML-escaped the source title and location but inserted the chunk text as is. A document containing</source>or</sources>could end the block early, and the rest of that chunk landed outside<sources>, right next to the question, where the "treat sources as reference material" rule no longer covers it.The fix: before rendering, the
<of any<source,</source,<sourcesor</sourcestag inside the text (any case) is replaced with<, so the renderer's own tags are the only real ones. Everything else in the text, including<,&and quotes in code, is left unchanged.How it was tested: new test
test_source_text_cannot_close_the_blockin backend/tests/test_llm.py; it failed before the fix (two</source>tags in the output). Locally ran what CI runs: ruff check, ruff format --check, mypy src, pytest (115 passed), and on the frontend npm ci, lint, typecheck, test, build:pages.Fixes #4