Component · L5
Eval Harness
github.com/juanmmm21/llm-eval-harness
An automated evaluation suite to benchmark LLM generation quality and detect regressions.
- Lines
- 439
- Files
- 6
- Test files
- 1
- Commits
- 10
- Started
- 26 Jun 2026
- Last commit
- 6 Jul 2026
- Python 100%
● Where it sits
Layer 5 of AI Core — mlops & quality.
L1 Data & input
L2 Representation & retrieval
L3 Inference & control
L4 Agents
L5 MLOps & quality
↳ Flagship
README · 3 min read
Commits per day
Automated response quality evaluation harness for language models (LLMs), designed to audit performance, establish accuracy baselines, and alert on behavioral regressions in continuous integration MLOps flows.
The module implements lexical text comparison metrics and n-gram overlap algorithms natively in Python, eliminating external network or storage dependencies and ensuring portable local execution.
Evaluator Architecture and Quality Metrics
The evaluation harness operates by contrasting the output generated by a model (candidate) against a golden reference dataset (ground-truth).
flowchart TD
Candidate[Candidate Response: c] --> Clean[Cleaning and Tokenization: clean_and_tokenize]
Reference[Reference Response: r] --> Clean
Clean --> JaccardAlg[Jaccard Similarity]
Clean --> CosineAlg[Bag-of-Words Cosine Similarity]
Clean --> BLEUAlg[BLEU-4 Algorithm with Smoothing]
Clean --> RatioAlg[Length Ratio]
Clean --> EMAlg[Exact Match]
JaccardAlg & CosineAlg & BLEUAlg & RatioAlg & EMAlg --> MetricReport[Individual MetricReport]
MetricReport --> Aggregator[Dataset Evaluation Summary]
subgraph CI/CD Regression Control
Aggregator --> BaselineComp{Does a previous Baseline exist?}
BaselineComp -->|No| SaveBaseline[Save as baseline.json]
BaselineComp -->|Yes| CompareMetrics[Calculate Variation Delta]
CompareMetrics --> RegressionCheck{Delta < -Tolerance?}
RegressionCheck -->|Yes| Alarm[Trigger Regression Alert - Build Failure]
RegressionCheck -->|No| Success[Approve Evaluation - Successful Pass]
end1. Quality Metric Specifications
The LLMEvaluator module synchronously computes five mathematical metrics to evaluate response fidelity:
- Exact Match (EM): Checks exact binary equality between the candidate and the reference after stripping leading/trailing whitespace and normalizing internal spaces:
- Jaccard Similarity: Calculates the overlap at the unique token set level between the candidate and the reference :
- Bag-of-Words Cosine Similarity: Models both texts as frequency vectors in the common vocabulary space : Where and are the absolute frequencies of term in the candidate and reference respectively.
- BLEU-4 Score (Bilingual Evaluation Understudy): Evaluates joint n-gram precision for .
- Clipped Precision (): Counts n-gram matches, capping the hit count at the maximum n-gram frequency observed in the reference to prevent false positives from fraudulently repeated words:
- Brevity Penalty (BP): Penalizes responses that are excessively short compared to the reference:
- Smoothing: If a higher-order n-gram ( or ) lacks exact matches, Laplace smoothing is applied by assigning instead of absolute zero, in order to allow evaluation of short sentences.
- Final BLEU Score: Where is the uniform weight distribution.
- Length Coherence Ratio: Measures the word-count proportion to audit verbose hallucinations or truncated responses:
2. Regression Detection in MLOps Pipelines
The harness acts as an automatable Quality Gate:
- Baseline: Allows exporting the average evaluation results to a local JSON file, configuring it as the certified stable behavior signature.
- Deviation Comparison (Delta): In subsequent runs, the system calculates the relative difference of each averaged metric:
- Regression Alert: If is below the configured negative tolerance threshold (for example, , representing a 5% loss in model quality), the harness reports a safety alarm that can be configured to abort the model's integration or deployment on the CI/CD branch.
Connection to the Ecosystem
This component validates the results of:
- llm-qlora-finetuner: Evaluates whether applying LoRA adapters and NF4 inference causes semantic degradation in the quantized model's generation compared to the dataset's original golden texts.
- llm-inference-server / orchestra-agents: Allows auditing that the responses emitted by the server's inference threads or the autonomous agents' conclusions remain aligned with historical quality metrics.
Project Structure
evaluator.py: Contains the definitions of the Pydantic-basedMetricReportandDatasetEvaluationSummaryclasses, as well as theLLMEvaluatorclass with the normalization and mathematical calculation methods.test_eval.py: Unit test suite that checks the accuracy of the Jaccard, cosine, and BLEU-4 formulas against edge cases and the correct interception of regression alarms.example.py: Interactive code that simulates the evaluation of a base model, the export of its JSON baseline, the subsequent evaluation of an experimentally degraded model, and the breakdown of alerts in the console.
Installation and Execution
1. Activate Local Environment and Install Dependencies
Since all mathematical formulas are implemented natively in Python using basic NumPy, no GPU hardware is required:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
2. Run Automated Tests
Check the correct functioning of the text comparison algorithms and the regression alert logic:
.venv/bin/python -m unittest test_eval.py
3. Run MLOps Evaluation Demo
.venv/bin/python example.py
The script will simulate a complete MLOps cycle: it will establish a baseline, evaluate an alternative candidate model, and display in detail the degradation alerts, calculating the exact deviation percentage.