Skip to content

Exact String Match

Check if output exactly matches expected text
Heuristic Single Turn Binary

At a Glance

🎯
Score Range
0.0 or 1.0
Binary pass/fail
⚡
Default Threshold
0.5
Pass/fail cutoff
đź“‹
Required Inputs
actual_output expected_output
Full text comparison

What It Measures

Exact String Match checks whether the actual output is identical to the expected output (after stripping whitespace). This is the strictest form of text matching—the response must be exactly what was expected.

Score Interpretation
1.0 Perfect match—strings are identical
0.0 No match—any difference fails
âś… Use When
  • Exact output format is required
  • Testing deterministic transformations
  • Validating code generation
  • Comparing structured outputs (JSON, XML)
❌ Don't Use When
  • Minor variations are acceptable
  • Semantic equivalence matters more
  • Paraphrasing is allowed
  • Case differences should be ignored

See Also: Contains Match

Exact String Match checks if actual equals expected. Contains Match checks if expected is a substring of actual.

Use Exact Match when precision matters; use Contains Match for keyword validation.


How It Works

Simple string equality check after stripping whitespace.

Step-by-Step Process

flowchart TD
    subgraph INPUT["📥 Inputs"]
        A[Actual Output]
        B[Expected Output]
    end

    subgraph PROCESS["🔍 Processing"]
        C[Strip whitespace]
        D["Check: actual == expected?"]
    end

    subgraph OUTPUT["📊 Result"]
        E["1.0 = Match"]
        F["0.0 = No Match"]
    end

    A & B --> C
    C --> D
    D -->|Yes| E
    D -->|No| F

    style INPUT stroke:#f59e0b,stroke-width:2px
    style PROCESS stroke:#3b82f6,stroke-width:2px
    style OUTPUT stroke:#10b981,stroke-width:2px
score = 1.0 if actual.strip() == expected.strip() else 0.0

Configuration

Parameter Type Default Description
(none) - - No configuration options

Simple by Design

Exact String Match is intentionally simple with no configuration. For case-insensitive or fuzzy matching, use Levenshtein Ratio.


Code Examples

from axion.metrics import ExactStringMatch
from axion.dataset import DatasetItem

metric = ExactStringMatch()

item = DatasetItem(
    actual_output="Hello, World!",
    expected_output="Hello, World!",
)

result = await metric.execute(item)
print(result.score)  # 1.0 - exact match
from axion.metrics import ExactStringMatch

metric = ExactStringMatch()

item = DatasetItem(
    actual_output="Hello, world!",  # lowercase 'w'
    expected_output="Hello, World!",  # uppercase 'W'
)

result = await metric.execute(item)
print(result.score)  # 0.0 - case mismatch
from axion.metrics import ExactStringMatch
from axion.runners import MetricRunner

metric = ExactStringMatch()
runner = MetricRunner(metrics=[metric])
results = await runner.run(dataset)

exact_matches = sum(1 for r in results if r.score == 1.0)
print(f"Exact matches: {exact_matches}/{len(results)}")

Example Scenarios

âś… Scenario 1: Perfect Match (Score: 1.0)

Identical Strings

Expected: "The answer is 42."

Actual: "The answer is 42."

Result: 1.0

Strings are character-for-character identical.

❌ Scenario 2: Case Mismatch (Score: 0.0)

Different Case

Expected: "PASS"

Actual: "Pass"

Result: 0.0

Case sensitivity causes failure.

⚠️ Scenario 3: Whitespace Handling

Leading/Trailing Whitespace

Expected: " Hello "

Actual: "Hello"

Result: 1.0

Whitespace is stripped before comparison, so these match.

❌ Scenario 4: Extra Content (Score: 0.0)

Additional Text

Expected: "Paris"

Actual: "The answer is Paris."

Result: 0.0

Even containing the expected text, the strings aren't equal.


Why It Matters

⚡ Instant Results

O(n) string comparison. No external dependencies or LLM calls.

🎯 Maximum Precision

No false positives—only identical strings pass.

đź”§ Deterministic Testing

Perfect for testing deterministic transformations and code generation.


Quick Reference

TL;DR

Exact String Match = Is the output identical to the expected text?

  • Use it when: Exact output format is required (code, JSON, IDs)
  • Score interpretation: 1.0 = identical, 0.0 = any difference
  • Key behavior: Case-sensitive, whitespace-trimmed