|
|
Human Feedback Collection and Preference Tracking for LLM Apps
Author: Venkata Sudhakar
ShopMax India's AI shopping assistant gives product recommendations, but without feedback signals it is impossible to know which responses customers found helpful versus frustrating. Collecting structured human feedback - thumbs up, thumbs down, or explicit ratings - creates a data flywheel that reveals which prompt versions work best, which topics need improvement, and which agent behaviours to reinforce. This tutorial shows how to build a lightweight feedback API that captures preference signals and stores them for analysis.
The feedback system exposes two endpoints: one to log a response along with its context (question, answer, model, timestamp), and one to record a user preference (liked or disliked). Each feedback event is stored in PostgreSQL with a session_id so you can join responses with preferences. A summary endpoint aggregates like rates by topic, giving the product team a clear signal of where to focus prompt engineering effort next.
The example below builds the feedback API using FastAPI and SQLAlchemy for ShopMax India. Customers submit thumbs signals after each AI response, and the system tracks like rates per topic category.
It gives the following output,
POST /log -> {"status": "logged"}
POST /feedback -> {"status": "recorded"}
GET /summary ->
{
"returns": {"like_rate": "78.3%"},
"order_tracking": {"like_rate": "65.1%"},
"product_reco": {"like_rate": "82.7%"}
}
Add a prompt_version column to ResponseLog to track which prompt generated each response, so A/B test results map cleanly to feedback scores. Use the like_rate per topic as an automatic trigger: if returns drops below 60%, send a Slack alert to the prompt engineering team. For ShopMax India, weight feedback from high-value customers (order value above Rs 10,000) more heavily in your dashboard - their experience has greater business impact than one-off buyers.
|
|