# Fuzzy Matching - Specifications Examples

> Focused demonstration of fuzzy matching for AI output validation. This example shows: - High-threshold fuzzy matching (0.95) for near-exact matches - Medium-threshold fuzzy matching (0.45) for semantic similarity - Default threshold behavior when not specified - Using fuzzy matching to handle natur…

Canonical: https://tactus.anth.us/examples/specifications/fuzzy-matching/

::band{columns="document-hero wide"}

[Examples](/examples/) / [Specifications](/examples/specifications/) / Fuzzy Matching

# Fuzzy Matching

- Has Specs
- **Requires API Keys**

Focused demonstration of fuzzy matching for AI output validation. This example shows: - High-threshold fuzzy matching (0.95) for near-exact matches - Medium-threshold fuzzy matching (0.45) for semantic similarity - Default threshold behavior when not specified - Using fuzzy matching to handle natural language variation

::band{tone="muted" columns="example"}

## Source Code

```lua
World = Agent {
  model = "openai/gpt-4o-mini",
  system_prompt = "Your name is World."
}

Specification([[
Feature: Fuzzy Matching

  Scenario: High-threshold fuzzy match (nearly exact)
    Given the procedure has started
    And the message is "Hello, World!"
    And the agent "World" responds with "Hello! I'm World, nice to meet you!"
    When the procedure runs
    Then the output should fuzzy match "Hello! I'm World, nice to meet you!" with threshold 0.95

  Scenario: Medium-threshold fuzzy match (allows variation)
    Given the procedure has started
    And the message is "Hello, World!"
    And the agent "World" responds with "Hello! How can I assist you today?"
    When the procedure runs
    Then the output should fuzzy match "Hello! I'm World, nice to meet you!" with threshold 0.45

  Scenario: Default fuzzy match threshold
    Given the procedure has started
    And the message is "Hello, World!"
    And the agent "World" responds with "Hello! I'm World, nice to meet you!"
    When the procedure runs
    Then the output should fuzzy match "Hello! I'm World, nice to meet you!"
]])

local result = World({message = "Hello, World!"})
return (result and (result.output or result)) or ""
```

## Quick Start

Run the example:

```bash
tactus run 04-specifications/03-fuzzy-matching.tac
```

Test with mocks:

```bash
tactus test 04-specifications/03-fuzzy-matching.tac --mock
```

> **Note.** This example requires API keys. Set your `OPENAI_API_KEY` environment variable before running.

[View source on GitHub →](https://github.com/AnthusAI/Tactus-examples/blob/main/04-specifications/03-fuzzy-matching.tac)

::band{columns="neighbors"}

- [*← Previous Example* **Passing Specs**](/examples/specifications/passing-specs/)

::band{columns="cta"}

## Explore more examples

Learn Tactus through practical, runnable examples organized by topic.

::button{href="/examples/" label="View All Examples" size="lg"}
