Skip to content

Conversation

@nimarb
Copy link
Contributor

@nimarb nimarb commented Jun 24, 2025

Important

Adds support for chat message placeholders in langfuse-python SDK, enabling dynamic templating in prompts with comprehensive test coverage.

  • Behavior:
    • Introduces ChatMessageWithPlaceholders type in chat_message_with_placeholders.py to handle both regular and placeholder messages.
    • Updates create_prompt_request.py and chat_prompt.py to use ChatMessageWithPlaceholders for prompt creation.
    • Adds PlaceholderMessage model in placeholder_message.py for template variables.
  • Functionality:
    • Modifies ChatPromptClient in model.py to compile prompts with placeholders, handling unresolved placeholders by logging warnings.
    • Enhances get_langchain_prompt() to convert unresolved placeholders to MessagesPlaceholder objects.
  • Testing:
    • Adds tests in test_prompt.py and test_prompt_compilation.py to cover placeholder scenarios, including edge cases and integration with Langchain.

This description was created by Ellipsis for 1c093d2. You can customize this summary. It will automatically update as commits are pushed.


Greptile Summary

Disclaimer: Experimental PR review

Implements chat message placeholder functionality in the langfuse-python SDK, enabling dynamic templating in chat prompts. This feature is critical for scenarios like injecting conversation history or examples into prompts.

  • Added ChatMessageWithPlaceholders union type in langfuse/api/resources/prompts/types/chat_message_with_placeholders.py supporting both regular chat messages and placeholder messages
  • Modified prompt creation to use ChatMessageWithPlaceholders instead of ChatMessage in langfuse/api/resources/prompts/types/create_prompt_request.py
  • Added new PlaceholderMessage Pydantic model in langfuse/api/resources/prompts/types/placeholder_message.py for template variables
  • Added comprehensive test coverage in tests/test_prompt.py for placeholder scenarios and edge cases

@nimarb nimarb marked this pull request as ready for review June 25, 2025 16:47
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

) -> None:
"""Backward-compatible setter for raw prompt structure."""
for p in prompt:
if hasattr(p, "type") and hasattr(p, "name") and p.type == "placeholder":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using hasattr(p, ...) in the prompt setter may fail for plain dict inputs which lack attribute access. Consider checking if p is a dict (e.g. using 'if isinstance(p, dict) and "type" in p') to support both dicts and objects.

@hassiebp hassiebp merged commit 3447a01 into main Jul 2, 2025
8 of 10 checks passed
@hassiebp hassiebp deleted the nimar/lfe-5387-message-placeholder-python branch July 2, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants