From a39db971c8b58d46bcfcf8f85ae53d7d78af75d1 Mon Sep 17 00:00:00 2001 From: moneebullah25 Date: Fri, 9 Oct 2026 08:19:05 -0400 Subject: [PATCH 1/2] fix(prompts): use each non-dict placeholder item as message content in compile --- langfuse/model.py | 2 +- tests/unit/test_prompt.py | 2 +- tests/unit/test_prompt_compilation.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/langfuse/model.py b/langfuse/model.py index 69d721597..f48fbff85 100644 --- a/langfuse/model.py +++ b/langfuse/model.py @@ -362,7 +362,7 @@ def compile( compiled_messages.append( ChatMessageDict( role="NOT_GIVEN", - content=str(placeholder_value), + content=str(msg), ) ) no_role_content_in_placeholder = f"Placeholder '{placeholder_name}' should contain a list of chat messages with 'role' and 'content' fields. Appended as string." diff --git a/tests/unit/test_prompt.py b/tests/unit/test_prompt.py index eadfb8221..c0e4bc34b 100644 --- a/tests/unit/test_prompt.py +++ b/tests/unit/test_prompt.py @@ -87,7 +87,7 @@ 4, [ "You are a helpful assistant", - "['invalid message', {'role': 'user', 'content': 'valid message'}]", + "invalid message", "valid message", "Help me with coding", ], diff --git a/tests/unit/test_prompt_compilation.py b/tests/unit/test_prompt_compilation.py index 1b96a14dd..ee18d07aa 100644 --- a/tests/unit/test_prompt_compilation.py +++ b/tests/unit/test_prompt_compilation.py @@ -932,3 +932,21 @@ def test_tool_calls_preservation_in_message_placeholder(): # Final user message with compiled variable assert compiled_messages[4]["role"] == "user" assert compiled_messages[4]["content"] == "Help me with weather inquiry" + + +def test_non_dict_placeholder_items_each_get_own_message(): + prompt = ChatPromptClient( + Prompt_Chat( + name="p", + version=1, + type="chat", + config={}, + labels=[], + tags=[], + prompt=[{"type": "placeholder", "name": "history"}], + ) + ) + + compiled = prompt.compile(history=["a", "b"]) + + assert [m["content"] for m in compiled] == ["a", "b"] From 6f3893d45a9e876330f5ae8e67eda4b31cc674cf Mon Sep 17 00:00:00 2001 From: moneebullah25 Date: Fri, 9 Oct 2026 10:42:30 -0400 Subject: [PATCH 2/2] test(prompts): use descriptive prompt name in placeholder non-dict items test --- tests/unit/test_prompt_compilation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_prompt_compilation.py b/tests/unit/test_prompt_compilation.py index ee18d07aa..3a22438bb 100644 --- a/tests/unit/test_prompt_compilation.py +++ b/tests/unit/test_prompt_compilation.py @@ -937,7 +937,7 @@ def test_tool_calls_preservation_in_message_placeholder(): def test_non_dict_placeholder_items_each_get_own_message(): prompt = ChatPromptClient( Prompt_Chat( - name="p", + name="placeholder_non_dict_items_test", version=1, type="chat", config={},