LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-classicevaluationparsingjson_distanceJsonEditDistanceEvaluator
    Class●Since v1.0

    JsonEditDistanceEvaluator

    An evaluator that calculates the edit distance between JSON strings.

    This evaluator computes a normalized Damerau-Levenshtein distance between two JSON strings after parsing them and converting them to a canonical format (i.e., whitespace and key order are normalized). It can be customized with alternative distance and canonicalization functions.

    Copy
    JsonEditDistanceEvaluator(
      self,
      string_distance: Callable[[str, str], float] | None = None,
      canonicalize: Callable[[Any], Any] | None = None,
      **_: Any = {}
    )

    Bases

    StringEvaluator

    Parameters

    NameTypeDescription
    string_distanceCallable[[str, str], float] | None
    Default:None

    A callable that computes the distance between two strings. If not provided, a Damerau-Levenshtein distance from the rapidfuzz package will be used.

    canonicalizeCallable[[Any], Any] | None
    Default:None

    A callable that converts a parsed JSON object into its canonical string form. If not provided, the default behavior is to serialize the JSON with sorted keys and no extra whitespace.

    Constructors

    constructor
    __init__
    NameType
    string_distanceCallable[[str, str], float] | None
    canonicalizeCallable[[Any], Any] | None

    Attributes

    attribute
    requires_input: bool
    attribute
    requires_reference: bool
    attribute
    evaluation_name: str

    Inherited fromStringEvaluator

    Methods

    Mevaluate_strings
    —

    Evaluate Chain or LLM output, based on optional input and label.

    Maevaluate_strings
    —

    Asynchronously evaluate Chain or LLM output, based on optional input and label.

    View source on GitHub