fix(langchain): silence intentional placeholder warnings#1689
Open
fengjikui wants to merge 1 commit into
Open
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.
Summary
ChatPromptClient.compile()calls.get_langchain_prompt()when unresolved placeholders are intentionally returned as LangChainMessagesPlaceholderobjects.Fixes #1667.
Verification
uv run --frozen pytest tests/unit/test_prompt_compilation.py::TestLangchainPromptCompilation::test_get_langchain_prompt_with_unresolved_placeholders -quv run --frozen pytest tests/unit/test_prompt_compilation.py -quv run --frozen ruff check langfuse/model.py tests/unit/test_prompt_compilation.pyuv run --frozen ruff format --check langfuse/model.py tests/unit/test_prompt_compilation.pyuv run --frozen mypy langfuse --no-error-summarygit diff --checkI also tried
uv run --frozen pytest tests/e2e/test_prompt.py::test_warning_on_unresolved_placeholders -q, but the local run requires Langfuse server credentials/API setup and failed before the assertion path withLangfuse client initialized without public_key.Greptile Summary
This PR fixes spurious
langfuse_logger.warningcalls that fire duringget_langchain_prompt()when unresolved placeholders are intentionally left for LangChain to handle asMessagesPlaceholderobjects.compile()is refactored into a thin wrapper around a new private_compile(warn_on_unresolved_placeholders: bool)method; the public API is unchanged and still warns by default.get_langchain_prompt()now calls_compile(warn_on_unresolved_placeholders=False), suppressing the warning only on the LangChain hand-off path.langfuse_logger.warningis never called duringget_langchain_prompt()when a placeholder is intentionally left unresolved.Confidence Score: 4/5
Safe to merge; the behavioural change is narrow and well-tested.
The refactor correctly isolates warning behaviour behind a flag, public compile() is unchanged, and a targeted regression test covers the silent path. The only finding is a style-level import placed inside a test method body rather than at the module top.
No files require special attention beyond the minor import placement in the test.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["compile(kwargs)"] -->|"warn=True"| B["_compile()"] C["get_langchain_prompt(kwargs)"] -->|"warn=False"| B B --> D{placeholder resolved?} D -- Yes --> E[expand messages] D -- No --> F[keep as placeholder dict] F --> G{warn flag set?} G -- Yes --> H["langfuse_logger.warning()"] G -- No --> I[silent] A --> L[return raw dicts] C --> M["convert to LangChain tuples / MessagesPlaceholder"]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(langchain): silence intentional plac..." | Re-trigger Greptile
Context used:
Learned From
langfuse/langfuse-python#1387