Skip to main content

Overview

This example demonstrates how to test AI chat responses using LLMJudge for semantic validation. Instead of exact text matching, we validate that responses meet behavioral expectations.

Complete Test

test.json

Setup

You’ll need an OpenAI API key:
.env

Running the Test

Expected output:

Breaking It Down

Good Response Test

1

Mock AI Response

Simulate a successful AI response with tool calls:
2

Semantic Validation

Use LLMJudge to validate the response semantically:
3

Assert High Score

Verify the AI response meets quality threshold:

Bad Response Detection

The second test verifies that poor responses get low scores, ensuring your LLMJudge criteria are working correctly:
This incomplete response should score below 0.4 because it:
  • Doesn’t use required tools
  • Doesn’t provide requested information
  • Fails to complete the task

Custom Criteria

Adjust scoring weights based on what matters most:

Real-World Usage

Testing OpenAI Chat API

Cost Considerations

LLMJudge uses GPT-4o-mini by default, which costs approximately:
  • ~$0.0001 per evaluation
  • ~$0.001 for 10 tests
  • ~$0.10 for 1000 tests
For production CI/CD, consider:
  1. Testing a sample of responses (not every one)
  2. Using faster traditional validation where possible
  3. Running full semantic tests nightly

Next Steps

Semantic Validation

Deep dive into LLMJudge

Tool Call Validation

Validate AI tool usage

Calendar Agent

Complete calendar agent example

LLMJudge Block

Complete LLMJudge documentation