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..3a22438bb 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="placeholder_non_dict_items_test", + 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"]