Skip to content

bmel:levenshtein-distance

Category: String · Returns: bmel:integer

Signature
bmel:levenshtein-distance(a: bmel:string, b: bmel:string)

Description

Returns the Levenshtein edit distance between two strings: the minimum number of single-character insertions, deletions, or substitutions required to transform a into b. Useful for detecting hallucinations by comparing LLM output against a known ground-truth string, or for measuring output stability across repeated calls.

Arguments

Parameter Type Required Description
a bmel:string Source string.
b bmel:string Target string.

Examples

Edits between the expected and the actual answer
bmel:levenshtein-distance({invokeAgent:Request Payload}.$.expected_output, {invokeAgent:Response Payload}.$.output_text)
Exact match, ignoring case
bmel:levenshtein-distance(bmel:lower({invokeAgent:Request Payload}.$.expected_output), bmel:lower({invokeAgent:Response Payload}.$.output_text)) == 0

← Back to BMEL Reference