Skip to main contentğŸ¦œï¸�ğŸ”— LangChainDocsUse casesIntegrationsAPILangSmithJS/TS DocsCTRLKGet startedIntroductionInstallationQuickstartModulesModel I/â€‹OData connectionChainsMemoryAgentsCallbacksModulesGuidesEvaluationString EvaluatorsEvaluating Custom CriteriaCustom String EvaluatorEmbedding DistanceQA CorrectnessString DistanceComparison EvaluatorsTrajectory EvaluatorsExamplesDebuggingDeploymentLangSmithModel ComparisonEcosystemAdditional resourcesGuidesEvaluationString EvaluatorsString DistanceOn this pageString DistanceOne of the simplest ways to compare an LLM or chain's string output against a reference label is by using string distance measurements such as Levenshtein or postfix distance.  This can be used alongside approximate/fuzzy matching criteria for very basic unit testing.This can be accessed using the string_distance evaluator, which uses distance metric's from the rapidfuzz library.Note: The returned scores are distances, meaning lower is typically "better".For more information, check out the reference docs for the StringDistanceEvalChain for more info.# %pip install rapidfuzzfrom langchain.evaluation import load_evaluatorevaluator = load_evaluator("string_distance")evaluator.evaluate_strings(    prediction="The job is completely done.",    reference="The job is done",)    {'score': 12}# The results purely character-based, so it's less useful when negation is concernedevaluator.evaluate_strings(    prediction="The job is done.",    reference="The job isn't done",)    {'score': 4}Configure the String Distance Metricâ€‹By default, the StringDistanceEvalChain uses  levenshtein distance, but it also supports other string distance algorithms. Configure using the distance argument.from langchain.evaluation import StringDistancelist(StringDistance)