Production Evaluation: Monitoring Semantic Quality

Production Evaluation: Monitoring Semantic Quality

Master the art of real-time AI quality control. Learn how to use automated judges and user feedback loops to identify hallucinations and drift in your live application.

Production Evaluation: Monitoring Semantic Quality

The most terrifying moment for an LLM Engineer is the first day an agent goes live with real customers. Unlike a database, an AI can't "crash" with a clean error log; it can just start giving slightly worse advice over time. This is called Semantic Drift.

In this lesson, we will look at how to evaluate quality in real-time, using Automated Judges and User Feedback.


1. The Feedback Loop: The Gold Standard

The most accurate data you will ever receive is from your users. You must implement a feedback mechanism in your UI.

  • Explicit Feedback: Thumbs up/down buttons. (The "True Ground Truth").
  • Implicit Feedback: If the user asks the same question 3 times in different ways, they are likely frustrated with the first two answers.

2. LLM-as-a-Judge in Production

You can't have a human review every chat message. Instead, you use a "Supervisor" model to randomly sample 5% of your production logs and grade them.

What the Judge looks for:

  1. Faithfulness: Did the agent make up facts not found in the RAG context?
  2. Relevance: Did the agent actually answer the user's question, or just waffle?
  3. Safety: Did the agent reveal any internal system instructions?
graph TD
    A[Production Logs] --> B[Sampler: 5% of chats]
    B --> C[Judge: Claude 3.5 Sonnet]
    C --> D{Evaluation Report}
    D -- Low Score --> E[Alert Engineer]
    D -- High Score --> F[Save to Golden Dataset]

3. Detecting Hallucinations with "Entailment"

How do you programmatically check if a model is lying? We use NLI (Natural Language Inference).

  1. The Agent provides an answer.
  2. The System extracts the "Facts" from that answer.
  3. The System checks if those facts are "Entailed" (logically supported) by the RAG context.
  4. If a fact is not supported, it is flagged as a potential hallucination.

4. Cost vs. Quality Monitoring

Quality doesn't exist in a vacuum. You must track Quality-per-Dollar. If your "Faithfulness Score" is 99% but each response costs $0.50, you might want to see if you can get 98% faithfulness for $0.05 using a smaller model and better prompting.


Code Concept: A Production Quality Logger

def log_production_interaction(user_input, model_output, context):
    # 1. Log to your DB (Postgres/BigQuery)
    db.save_log(user_input, model_output)
    
    # 2. Asynchronously run a quality check
    if random_sample(0.05):
        grade = run_judge(user_input, model_output, context)
        if grade < 3: # Out of 5
            send_alert(f"Low quality response detected: Request ID {id}")

Summary

  • User Feedback is the most valuable signal for long-term improvement.
  • LLM-as-a-Judge allows you to scale your qualitative monitoring.
  • Semantic Drift must be monitored daily to ensure models haven't become "stale" or "weird."
  • Hallucinations can be automatically detected using NLI (Entailment) checks.

In the next lesson, we will look at Monitoring and Logging, focusing on the technical stack needed to store and analyze these logs.


Exercise: The Feedback Miner

Your AI support bot is getting 1,000 "Thumbs Down" ratings a day. The users' comments say: "It's too talkative."

Draft a plan to fix this:

  1. How do you find the specific part of your system prompt caused the verbosity?
  2. How do you use the "LLM-as-a-Judge" to verify your fix before deploying it?

Answer Logic:

  1. Log Analysis: Extract the "Thumbs Down" chats and find the average word count.
  2. Evaluation: Re-run those 1,000 headers through your new "Concise Prompt" and have GPT-4o compare the "New" vs "Old" based on a "Conciseness Score."

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn