Regex Evaluators
Overview
Section titled “Overview”Regex evaluators match patterns in LLM responses to extract and score answers. Three modes are available: regex-only, LLM-prompt, and hybrid.
Built-in Evaluators
Section titled “Built-in Evaluators”regex_number_extractor
Section titled “regex_number_extractor”Extracts numeric answers from responses.
{ "id": "regex_number_extractor", "type": "regex", "extraction_regex": "(?:Jawaban|Score|Answer|Nilai):?\\s*(\\d+(?:\\.\\d+)?)"}Matches: Jawaban: 42, Score: 85.5, Answer: 100
regex_exact_match
Section titled “regex_exact_match”Matches entire response against expected string (case-insensitive).
{ "id": "regex_exact_match", "type": "regex", "extraction_regex": "^(.+)$"}regex_multiple_choice
Section titled “regex_multiple_choice”Extracts A/B/C/D answers.
{ "id": "regex_multiple_choice", "type": "regex", "extraction_regex": "(?:Jawaban|Answer):?\\s*([ABCDabcd])"}regex_date_extractor
Section titled “regex_date_extractor”Validates YYYY-MM-DD date format.
{ "id": "regex_date_extractor", "type": "regex", "extraction_regex": "(\\d{4}-\\d{2}-\\d{2})"}regex_sql_validator
Section titled “regex_sql_validator”Checks for SELECT…FROM…WHERE structure.
{ "id": "regex_sql_validator", "type": "regex", "extraction_regex": "(?i)\\b(SELECT)\\b.*\\b(FROM)\\b.*\\b(WHERE)\\b"}hybrid_quality_rater
Section titled “hybrid_quality_rater”LLM evaluates quality, regex extracts the score.
{ "id": "hybrid_quality_rater", "type": "hybrid", "eval_prompt": "Evaluate response quality 0-100:\n\nResponse: {response}\nExpected: {expected}\n\nEnd with: SCORE: <number>", "extraction_regex": "SCORE:\\s*(\\d+)"}How Scoring Works
Section titled “How Scoring Works”Mode 1: Score Extraction (captures a number)
Section titled “Mode 1: Score Extraction (captures a number)”- Extract value from first capture group
- Normalize: >100 → divide by 100; >5 → assume 0-100 scale
- Status:
passedif score >= 0.7
Mode 2: String Matching (captures text + expected exists)
Section titled “Mode 2: String Matching (captures text + expected exists)”- Extract from first capture group
- Compare with expected (case-insensitive)
- Score: 1.0 if match, 0.0 if not
Mode 3: Full Match (no capture groups)
Section titled “Mode 3: Full Match (no capture groups)”- Check if pattern matches anywhere in response
- Score: 1.0 if found, 0.0 if not
Creating Custom Regex Evaluators
Section titled “Creating Custom Regex Evaluators”Via the Settings UI
Section titled “Via the Settings UI”- Go to Settings → Evaluators tab
- Click + Add Custom Evaluator
- Select type: Regex Pattern Matcher
- Enter your extraction regex pattern
Via JSON File
Section titled “Via JSON File”Create a file in test_definitions/evaluators/:
{ "id": "my_custom_regex", "name": "My Custom Evaluator", "type": "regex", "description": "What it evaluates", "extraction_regex": "your-regex-here", "uses_pass2": false, "config": {}}Common Patterns
Section titled “Common Patterns”| Pattern | Purpose |
|---|---|
(?:Answer):?\s*(\d+) | Extract number after “Answer:“ |
(\d+(?:\.\d+)?)\s*% | Extract percentage |
([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}) | Extract email |
(https?:\/\/[^\s]+) | Extract URL |
(\d{4}-\d{2}-\d{2}) | Extract date (YYYY-MM-DD) |
(\d{2}:\d{2}) | Extract time (HH:MM) |
[Jj]awaban:\s*([ABCD]) | Multiple choice answer |
(?i)\b(SELECT)\b.*\b(FROM)\b | SQL keyword validation |
- Always use capture groups
(...)to extract specific values - Use
(?i)for case-insensitive matching - Test patterns at regex101.com before deploying
- Remember JSON requires double backslashes (
\\dnot\d)