How to extract dynamic "last user message" from chat history for Evaluation? #11023
Replies: 3 comments 1 reply
-
|
There is no documented way to select “the last user message” via JSONPath in the evaluator mapping today, so you cannot reliably do this with something like From what is documented, there are two practical patterns:
Given the current behavior:
So for your case (dynamic last user message in a variable-length messages array), the best-practice options within documented behavior are:
There is no documented way to express “last element of the array” directly in the evaluator mapping UI today. 📚 Sources:
Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @VeronikaSus was inkeep helpful here? Do you require further assistance? |
Beta Was this translation helpful? Give feedback.
-
|
hey how can we get set of messages I'm defining evals in which i wanted to define past messages for which i need all messages except last on, how to define this |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe your question
Hi everyone, I'm struggling with mapping the correct input for LLM-as-a-judge evaluators in a multi-turn chat application.
My trace input is a standard list of messages (System, User, Assistant, Tool, User...). The length of this array varies per trace.
// Example Trace Input
[
{"role": "system", "content": "..."},
{"role": "user", "content": "First question"},
{"role": "assistant", "content": "..."},
{"role": "user", "content": "Review this please"} // <--- I need this dynamic last message
]
I need to map the last user message to the Evaluator's {{input}} variable. Since the conversation length varies, I cannot use a hardcoded index like input[1].content.
I tried using standard JSONPath features like negative indices: $.input[-1].content, but it seems Langfuse's JSONPath implementation doesn't support negative indexing or filtering.
My Question: What is the best practice for evaluating multi-turn conversations where the user input is at a dynamic index?
Is there a way to target the last item in the input array via Langfuse mapping?
Or should I pass the entire input JSON array to the LLM judge and let the prompt handle the extraction?
Thanks for any tips!
Langfuse Cloud or Self-Hosted?
Langfuse Cloud
If Self-Hosted
No response
If Langfuse Cloud
https://cloud.langfuse.com/project/cmgxcpp4u02x8ad06o4yxfpwi
SDK and integration versions
No response
Pre-Submission Checklist
Beta Was this translation helpful? Give feedback.
All reactions