Repository navigation
Conversation
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.
Description
Fixes #23685.
PromptTemplate.partial_format()clears the source template's parser before copying and restores it only on success. If another value cannot be copied, subsequent calls on the original prompt silently lose their output instructions.ChatPromptTemplate.partial_format()has the opposite inconsistency: it copies the parser itself, so parsers containing locks or non-copyable client state fail to partially format.Use
deepcopy's memo to preserve the parser by identity while copying the other template state. Both template types now retain their parser without temporarily mutating the source. Other copy errors still propagate and leave the original prompt usable. Text-template parser sharing is preserved; chat templates now follow the same behavior.Validation
619d74664: 2 failed, 2 passed in the new regression module. Chat partial formatting fails on the parser's lock, and failed text partial formatting leavesoutput_parser=None.PYTHONPATH=$PWD python -m pytest tests/prompts/test_base.py tests/prompts/test_utils.py tests/prompts/test_partial_format_parser.py -q --tb=short: 15 passed.tests/promptsrun: 28 passed, 5 setup errors. All five setup errors are the existing rich-prompt PDF fixture'shttpx.get(pdf_url)being rejected by the environment proxy with HTTP 403. They are not counted as passes.git diff --check, and targeted mypy with--follow-imports=skipon both changed files: passed. Full repository typechecking/CI was not run locally.Core-only change; no version bump or new dependency.
AI assistance was used for investigation, implementation and regression tests. Verified both baseline failures and their controls, reviewed parser-sharing behavior, and ran the checks above. Submitted as draft for human review.