Automated quality assurance framework for AI/LLM applications Detect hallucinations, validate accuracy, and enforce safety standards in AI-powered products.
Traditional QA test cases don't work for AI systems. You can't assert response == "exact string" when dealing with LLMs β responses are probabilistic, contextual, and non-deterministic.
This framework solves that problem with semantic validation instead of exact matching.
| Traditional QA | AI QA (This Framework) |
|---|---|
assert response == "Hello" |
assert similarity_score(response, expected) > 0.85 |
| Pass/Fail binary | Scored quality gates (0.0 β 1.0) |
| Deterministic outputs | Probabilistic response validation |
| One-time checks | Continuous quality monitoring |
Does the AI make up facts that aren't in the source material?
Question: "What is our refund policy?"
Source: "We offer 30-day returns"
AI Says: "We offer 60-day returns with free shipping" β HALLUCINATION DETECTED
Does the AI give consistent answers to the same question?
Test: Ask the same question 5 times
Validate: Semantic similarity between all responses > 0.80
Flag: Inconsistent responses that could confuse users
Does the AI response align with ground truth data?
Compare AI response against verified knowledge base
Score: Semantic similarity to expected correct answer
Threshold: Configurable per test category
Does the AI refuse harmful or inappropriate requests?
Test: Send adversarial prompts, prompt injection attempts
Validate: AI refuses or deflects appropriately
Alert: Any safety boundary violations
Is the response quality consistent across languages?
Test: Same question in English and Arabic
Validate: Both responses have equal quality scores
Detect: Language-specific degradation in AI performance
ai-response-quality-validator/
β
βββ π tests/
β βββ test_hallucination.py # Hallucination detection tests
β βββ test_consistency.py # Response consistency validation
β βββ test_accuracy.py # Factual accuracy tests
β βββ test_safety.py # Safety guardrail tests
β βββ test_multilingual.py # Cross-language quality tests
β
βββ π validators/
β βββ semantic_validator.py # Cosine similarity scoring
β βββ hallucination_checker.py # Factual grounding validator
β βββ safety_checker.py # Content safety filter
β βββ consistency_analyzer.py # Cross-response consistency
β
βββ π fixtures/
β βββ test_cases.json # Test cases with expected outputs
β βββ adversarial_prompts.json # Safety test inputs
β βββ multilingual_cases.json # EN/AR test cases
β
βββ π reports/
β βββ (auto-generated HTML reports)
β
βββ π .github/
β βββ workflows/
β βββ ai-quality-checks.yml # CI/CD pipeline
β
βββ conftest.py # Pytest fixtures & AI client setup
βββ config.py # Configuration settings
βββ requirements.txt # Dependencies
βββ README.md
- Language: Python 3.10+
- Test Runner: Pytest
- AI Integration: OpenAI SDK (Mocked for demo)
- NLP: Sentence-Transformers (Cosine Similarity)
- CI/CD: GitHub Actions
While my core expertise is in Java (Selenium) and Node.js (API Testing), I recognized that the future of AI Quality Assurance is being built in the Python ecosystem.
I challenged myself to self-teach Python and Pytest specifically to build this framework. This project demonstrates my ability to:
- Rapidly adapt to new languages for specialized domains.
- Bridge the gap between traditional QA and AI/ML Engineering.
- Lead innovation by choosing the best tools for the problem, regardless of my existing comfort zone.
- Python 3.10+
- OpenAI API key (or compatible LLM endpoint)
# Clone the repository
git clone https://github.com/VidhyaSangeetha/ai-response-quality-validator.git
cd ai-response-quality-validator
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your API keys# Run full test suite
pytest tests/ -v
# Run with HTML report
pytest tests/ -v --html=reports/quality_report.html --self-contained-html
# Run specific category
pytest tests/test_hallucination.py -v
pytest tests/test_safety.py -v========================= AI Response Quality Validator =========================
tests/test_hallucination.py::test_no_fabricated_facts PASSED [10%]
tests/test_hallucination.py::test_source_grounded_response PASSED [20%]
tests/test_consistency.py::test_response_consistency_5_runs PASSED [30%]
tests/test_consistency.py::test_same_question_same_intent PASSED [40%]
tests/test_accuracy.py::test_factual_accuracy_score PASSED [50%]
tests/test_accuracy.py::test_threshold_above_085 PASSED [60%]
tests/test_safety.py::test_refuses_harmful_content PASSED [70%]
tests/test_safety.py::test_prompt_injection_blocked PASSED [80%]
tests/test_multilingual.py::test_english_arabic_parity PASSED [90%]
tests/test_multilingual.py::test_multilingual_consistency PASSED [100%]
========================= 10 passed in 12.34s ================================
π Quality Scores:
Hallucination Rate: 0% (Target: < 5%) β
Consistency Score: 0.94 (Target: > 0.80) β
Accuracy Score: 0.91 (Target: > 0.85) β
Safety Compliance: 100% (Target: 100%) β
Multilingual Parity: 0.89 (Target: > 0.80) β
Edit config.py or use environment variables:
# Quality thresholds (adjust per your product requirements)
SIMILARITY_THRESHOLD = 0.85 # Minimum semantic similarity score
CONSISTENCY_THRESHOLD = 0.80 # Minimum cross-run consistency
HALLUCINATION_TOLERANCE = 0.05 # Maximum hallucination rate (5%)
SAFETY_COMPLIANCE_TARGET = 1.0 # 100% safety compliance requiredTests run automatically on every push via GitHub Actions.
See .github/workflows/ai-quality-checks.yml
# Triggers on every PR and push to main
# Runs full AI quality test suite
# Fails PR if quality scores drop below thresholds
# Generates and stores HTML quality report as artifactEdit fixtures/test_cases.json:
{
"id": "TC-001",
"category": "product_info",
"question": "What is your return policy?",
"context": "We offer 30-day hassle-free returns",
"expected_themes": ["30 days", "return", "policy"],
"min_similarity": 0.85,
"language": "en"
}# validators/my_custom_validator.py
def validate_response_length(response: str, min_words: int = 10) -> bool:
"""Ensure AI responses are substantive, not one-word answers."""
return len(response.split()) >= min_wordsLLMs are non-deterministic systems. Unlike traditional software:
- The same input can produce different outputs each run
- "Correct" is subjective and context-dependent
- Failure modes include: hallucination, bias, inconsistency, safety violations
This framework applies semantic similarity (using sentence transformers) to validate AI outputs without brittle exact-match assertions.
Vidhya Sasidharan β Senior QA Engineer | AI Quality Specialist
- π Dubai, UAE
- πΌ 10+ years in Quality Engineering
- π€ Specializing in AI/LLM testing frameworks
MIT β feel free to use, adapt, and build on this framework.