What is Semantic Validation?
Semantic validation means checking if a response is correct in meaning, not just in exact wording.The Problem
The Solution: LLMJudge
LLMJudge uses OpenAI models to evaluate whether responses meet your semantic requirements:When to Use LLMJudge
- ✅ Use LLMJudge
- ❌ Don't Use LLMJudge
Non-deterministic text content:
- AI chat responses
- Generated summaries
- Creative content
- Explanations
- Natural language descriptions
Setup
1. Get OpenAI API Key
Sign up at platform.openai.com and create an API key.2. Set Environment Variable
.env file:
Cost: LLMJudge uses GPT-4o-mini by default (~0.001.
Basic Usage
Simple Validation
Expected Behavior Format
Be Specific
- ❌ Vague
- ✅ Specific
Include Key Details
Use Action Verbs
Good verbs: confirms, explains, lists, mentions, asks, provides, includes, summarizesCustom Scoring Criteria
Define your own scoring dimensions:Weights must sum to 1.0
Available Criteria
LLMJudge supports three scoring criteria. You can adjust their weights:Weights must sum to 1.0. The three criteria are hardcoded and cannot be customized, but you can adjust their relative importance by changing the weights.
Example Weight Adjustments
- Prioritize Accuracy
- Balanced
- Prioritize Completeness
Model Selection
Choose the right model for your use case:Model Comparison
| Model | Speed | Cost | Accuracy | Use Case |
|---|---|---|---|---|
| gpt-4o-mini | ⚡ Fast | 💰 $0.0001 | ⭐⭐⭐ Good | Recommended - Fast, cheap, accurate |
| gpt-4o | ⚡ Fast | 💰💰 $0.0025 | ⭐⭐⭐⭐ Better | Complex evaluations |
| gpt-4-turbo | 🐌 Slower | 💰💰💰 $0.01 | ⭐⭐⭐⭐⭐ Best | Critical validations |
Real-World Examples
1. Testing ChatGPT-Style Interface
2. Testing Content Summarization
3. Testing Code Generation
Cost Optimization
LLMJudge makes API calls to OpenAI. Here’s how to minimize costs:1. Use gpt-4o-mini
2. Combine with Traditional Validation
Don’t use LLMJudge for everything:3. Cache Common Validations
If testing same AI responses repeatedly during development:4. Test Samples in CI/CD
Best Practices
1. Be Specific in Expected Behavior
1. Be Specific in Expected Behavior
2. Be Specific About Requirements
2. Be Specific About Requirements
3. Set Appropriate Score Thresholds
3. Set Appropriate Score Thresholds
4. Combine Multiple Validation Types
4. Combine Multiple Validation Types
5. Include Context When Needed
5. Include Context When Needed
For conversations, pass history:
Troubleshooting
Low Scores Despite Good Responses
Problem: judgement.score is 0.6 but response looks good Solutions:- Make expectedBehavior more specific
- Lower score threshold:
{ "gte": 0.7 }instead of{ "gte": 0.9 } - Check if response actually meets expectations
High Costs
Problem: Test suite costs $5+ per run Solutions:- Switch to gpt-4o-mini
- Use traditional validation where possible
- Test fewer examples in CI
- Cache results during development
Inconsistent Scores
Problem: Same response gets different scores (0.85, then 0.78, then 0.92) Solution: This is normal with AI. Set threshold ranges:Missing Context
Problem: LLMJudge doesn’t understand multi-turn conversation Solution: Pass conversation history:Next Steps
Tool Call Validation
Learn to validate AI tool/function calls
Streaming Responses
Parse and test SSE streams from AI APIs
LLMJudge Block Reference
Complete LLMJudge documentation
AI Chat Example
Full example testing OpenAI chat API

