LangfuseLangfuse Python SDK 4.15.4 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson

What the customer thought

A trace says what the desk did. A score says whether it helped. Feedback from the customer is a score attached to the ticket's trace.

The ticket number gives the trace id, so feedback that arrives minutes later still lands on the right trace.

Examplesupport_desk.py, continued
def record_feedback(ticket_number, helpful, comment=None):
    langfuse = get_client()
    langfuse.create_score(
        trace_id=langfuse.create_trace_id(seed=ticket_number), score_id=f"{ticket_number}-feedback",
        name="user-feedback", value=1 if helpful else 0, data_type="BOOLEAN", comment=comment,
    )

The seed rebuilds the same id, and score_id is built from the ticket number too, so a customer who changes their mind replaces the old rating instead of adding a second one.

Examplefeedback.py, after the setup lines
support_desk.handle("ticket-1042", "Where is my order A17?", customer="cust-42", chat="chat-0042")
support_desk.record_feedback("ticket-1042", helpful=False, comment="B22 is on my receipt")

langfuse.flush()
print(local_langfuse.SCORES)
Example
python feedback.py

The score arrived with the trace id, a boolean value and the customer's words. Scores like this are what a weekly report counts, and what tells you which traces to read.

Try it yourself
  • Record feedback twice for one ticket and count the scores.
  • Add a second score with a different name on the same trace.
  • Record feedback for a ticket the desk never handled, and see what the server keeps.

You understood something today that you didn't yesterday.