-
Notifications
You must be signed in to change notification settings - Fork 1
Regex Assertions
Use a regex assertion when generated output must match a pattern rather than a fixed substring or complete string.
| Interface | Support |
|---|---|
| Dashboard | Author in the visual or JSON editor and inspect normalized results |
| Mix CLI | Evaluate stored or file-based suites with mix aludel.eval
|
| Elixir API | Evaluate inline or as part of a suite |
| ExUnit | Assert inline output or gate a persisted suite |
| CSV and JSON imports | Validate patterns before importing test cases |
All interfaces use the same matcher and result contract.
{"type": "regex", "value": "(?i)confidence: \\d+%"}Inline PCRE options such as (?i) are supported. A successful match returns a score of 100.0; a valid non-match returns 0.0 with Output does not match regular expression.
Open a suite test case, add an assertion, choose regex, and enter the pattern. The visual and raw JSON editors save the same assertion map. Invalid or oversized patterns are rejected before the test case is stored.
Evaluate already-generated output without creating a suite:
result =
Aludel.Evals.AssertionEvaluator.evaluate(
"Confidence: 92%",
%{"type" => "regex", "value" => "(?i)^confidence: \\d+%$"}
)
result["passed"]
#=> truePersisted suites use the same assertion map in each test case.
defmodule ResponseTest do
use ExUnit.Case
use Aludel.ExUnit
test "includes a confidence percentage" do
assert_evaluation(
"Confidence: 92%",
%{"type" => "regex", "value" => "(?i)^confidence: \\d+%$"}
)
end
endLimit failures follow the normal ExUnit.AssertionError path and keep generated output out of evaluator error details.
File-based manifests select a persisted suite whose test cases contain the regex assertion. They do not duplicate test-case definitions:
schema_version: 1
suite_id: 9a756a58-eaec-43ca-99e6-f5c016d85d0c
prompt_version_id: e74cf2e1-94b6-4bcb-9ed9-b259661be906
provider_id: e1c60ec0-6d55-419b-b958-7d088055254fRun it with mix aludel.eval --file evals/support-answer.yaml. Regex assertions need no separate CLI command or configuration.
Regex assertions are treated as untrusted input at both save time and execution time:
- patterns are limited to 4 KiB
- evaluated output is limited to 1 MiB
- backtracking work and depth are bounded
- each match has a 250 ms wall-clock ceiling
- assertion-provided PCRE limit directives cannot raise Aludel's limits
Aludel rejects rather than truncates oversized values so a shortened subject cannot produce a misleading pass. A size, complexity, depth, or timeout limit returns a normalized failed assertion with evaluator error type regex_resource_limit. Suite execution can continue with later assertions and test cases.
- Use
containsfor a literal substring without regex syntax. - Use
exact_matchwhen the entire output must equal one value. - Use
json_fieldorjson_deep_comparefor structured JSON. - Use
rubric_judgewhen correctness depends on meaning rather than format.
See Evaluation Suites, ExUnit Evaluations, and File-Based Suites for complete workflows.
- Prompts
- Providers
- Runs and Execution
- Evaluation Suites
- Regex Assertions
- Metric Context
- Evaluator Execution Details
- Rubric Judges
- Judge Catalog
- Repeated Sampling
- Quality Policies
- ExUnit Evaluations
- File-Based Suites
- Evaluation Reporters
- Datasets
- Red-Team Datasets
- Generated Red-Team Cases
- Analytics and Prompt Evolution
- Exports and CI
- Documents and Storage
- Embedding and Access