# langchain-ai/openevals architecture

> Architecture diagram of the GitHub repository langchain-ai/openevals, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/langchain-ai/openevals
- Repository: https://github.com/langchain-ai/openevals

## Overview

- Defining evaluators that check output correctness, conciseness, hallucination, and various code correctness metrics.
- Integrating with external LLM providers (e.g. OpenAI, Anthropic) via LangChain, and with sandboxed execution environments using E2B.
- Providing support for multiple evaluation strategies including exact match, string similarity (e.g., Levenshtein, embedding similarity) and specialized code evaluators (e.g. pyright, mypy, TypeScript type-checking).
- Incorporating logging and experiment tracking via LangSmith.

##### Major Components and Layers
- Evaluators Module (Core Library):
– LLM-as-Judge Evaluators: These use prebuilt prompts (e.g. for correctness, conciseness, hallucination) that format inputs/outputs, invoke an external LLM (provided by LangChain integrations), and parse the resulting score.
– Structured Output & JSON Evaluators: Handling exact match comparison and JSON “fuzzy” matching via both deterministic and LLM-based methods.
– String and Similarity Evaluators: Modules that compute metrics such as Levenshtein distance and embedding similarity.
– Code Evaluation Modules: Separated by language – Python code evaluators using tools like Pyright, Mypy, and sandboxed execution (via E2B), and TypeScript evaluators that use the built-in type checker as well as E2B sandbox counterparts.
- Utility and Extraction Helpers:
– Code extraction utilities (e.g. extracting markdown code blocks or using an LLM to extract code) embedded within the evaluators.
– Config files, test suites, and common utility functions for evaluator orchestration.
- Integration and Orchestration:
– LangSmith Integration: Wrappers for logging inputs/outputs, experiment details, and evaluator results.
– Asynchronous Support: Both Python async wrappers (noted by functions/methods such as create_async_llm_as_judge) and TypeScript’s async evaluators.
- External Dependencies & Services:
– LLM Providers (e.g. OpenAI, Anthropic) – these are used within evaluators.
– E2B Sandboxed Execution: External sandbox environments (set up in the “sandbox” folder) for safely running/typing code.
– External utilities such as LangChain models and embeddings.
– CI/CD integrations (example: .github/workflows).

##### File Structure
– “Python Module” representing the python/openevals directory: Its components include subfolders like code, prompts, json, string, and tests, along with integration files such as py.typed and pyproject.toml.
– “JavaScript/TypeScript Module” representing the js folder: This contains similar submodules for code logic, tests, prompts, and configuration (package.json, tsconfigs).
- Additionally, represent shared configuration (like GitHub workflows, .gitignore, LICENSE, README) and the “sandbox” folder as a separate module that interfaces with both language components.
- A “static” folder which holds assets (such as images used in documentation or for LangSmith reporting).

##### Relationships and Data Flow
- How evaluator factory functions (e.g. create_llm_as_judge, create_json_match_evaluator, create_embedding_similarity_evaluator) branch into specific evaluation strategies.
- Connections between evaluators and external services:
- Use connectors to denote the common logging/integration layer (LangSmith integration) that receives feedback from various evaluators.

##### Architectural Patterns and Design Principles
- Modularity and separation of concerns: each evaluator tries to encapsulate a specific evaluation metric. You might group similar evaluators in containers (for example, one container for “LLM Evaluators”, another for “Code Evaluators”).
- Consistent interfaces for evaluators (inputs, outputs, and reference outputs). A simple “Evaluator Interface” component can denote this standardized design.
- Asynchronous design support across the library as a design pattern for scalability.

##### Technologies and Frameworks
- In the JavaScript branch, include TypeScript, Yarn (as seen from .yarn and configuration files), and integration with NodeJS packages.
- In the Python branch, show Python’s package configuration (pyproject.toml) and integration with LangChain, OpenAI, pyright, and mypy.
- External API connections (e.g., to OpenAI and Anthropic) along with the LangSmith and E2B sandbox services.

- Clear labels for each component, e.g. “LLM-as-Judge Evaluator (Python)” and “LLM-as-Judge Evaluator (JS)”, “Code Extraction Utility”, “TypeScript Type-Checker Evaluator”, etc.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Nodes
    A["Client Applications"]:::client
    B["Evaluation Core Interface"]:::interface

    %% Python Module
    subgraph "Python Module"
        p1["LLM-as-Judge Evaluator (Python)"]:::evaluator
        p2["JSON Evaluators (Python)"]:::evaluator
        p3["Levenshtein (Python)"]:::evaluator
        p4["Embedding Similarity (Python)"]:::evaluator
        p5["Pyright Evaluator"]:::code
        p6["Mypy Evaluator"]:::code
        p7["Python E2B Sandbox"]:::sandbox
        p11["Python Sandbox"]:::sandbox
        p8["Prompts (Python)"]:::prompt
        p9["Utility Helpers (Python)"]:::utility
        p10["Python Tests"]:::test
    end

    %% JavaScript/TypeScript Module
    subgraph "JavaScript/TypeScript Module"
        j1["LLM-as-Judge Evaluator (JS)"]:::evaluator
        j2["JSON Evaluators (JS)"]:::evaluator
        j3["Levenshtein (JS)"]:::evaluator
        j4["Embedding Similarity (JS)"]:::evaluator
        j5["JS Code Evaluator"]:::code
        j6["JS E2B Sandbox"]:::sandbox
        j7["JS E2B Execution"]:::sandbox
        j8["TypeScript Checker Evaluator"]:::code
        j9["Prompts (JS)"]:::prompt
        j10["Utility Helpers (JS)"]:::utility
        j11["JS Tests"]:::test
        j12["LangChain Config (JS)"]:::config
    end

    %% Shared Components
    subgraph "Shared Components"
        s1["Shared Sandbox (E2B)"]:::sandbox
        s2["CI/CD Workflows"]:::cicd
        s3["Static Assets"]:::asset
        s4["LangSmith Integration"]:::integration
    end

    %% External Services
    ext1["LLM Providers"]:::external

    %% Connections from Client and Core
    A --> B
    B --> p1
    B --> p2
    B --> p3
    B --> p4
    B --> p5
    B --> p6
    B --> j1
    B --> j2
    B --> j3
    B --> j4
    B --> j5
    B --> j12

    %% Evaluators contacting External LLM Providers
    p1 -->|"calls"| ext1
    j1 -->|"calls"| ext1

    %% Code Evaluators using Sandbox (Python)
    p5 -->|"uses"| p7
    p6 -->|"uses"| p7
    p7 -->|"enhanced by"| p11
    %% Code Evaluators using Sandbox (JS)
    j5 -->|"uses"| j6
    j6 -->|"executes in"| j7
    j6 -->|"validates with"| j8

    %% Prompts feeding evaluators
    p8 -->|"guides"| p1
    p8 -->|"guides"| p2
    p8 -->|"guides"| p3
    p8 -->|"guides"| p4
    j9 -->|"guides"| j1
    j9 -->|"guides"| j2
    j9 -->|"guides"| j3
    j9 -->|"guides"| j4

    %% Evaluators send results to LangSmith Integration
    p1 -->|"logs"| s4
    p5 -->|"logs"| s4
    p2 -->|"logs"| s4
    j1 -->|"logs"| s4
    j5 -->|"logs"| s4

    %% Testing connected to CI/CD
    p10 -->|"triggers"| s2
    j11 -->|"triggers"| s2

    %% Sandbox integration to Shared Sandbox
    p7 -->|"reports to"| s1
    j6 -->|"reports to"| s1

    %% Shared Components linked with Static Assets (for reporting/documentation)
    s4 -->|"updates"| s3

    %% Click Events for Python Components
    click p1 "https://github.com/langchain-ai/openevals/blob/main/python/openevals/llm.py"
    click p2 "https://github.com/langchain-ai/openevals/blob/main/python/openevals/json/match.py"
    click p3 "https://github.com/langchain-ai/openevals/blob/main/python/openevals/string/levenshtein.py"
    click p4 "https://github.com/langchain-ai/openevals/blob/main/python/openevals/string/embedding_similarity.py"
    click p5 "https://github.com/langchain-ai/openevals/blob/main/python/openevals/code/pyright.py"
    click p6 "https://github.com/langchain-ai/openevals/blob/main/python/openevals/code/mypy.py"
    click p7 "https://github.com/langchain-ai/openevals/tree/main/python/openevals/code/e2b/"
    click p8 "https://github.com/langchain-ai/openevals/tree/main/python/openevals/prompts/"
    click p9 "https://github.com/langchain-ai/openevals/blob/main/python/openevals/utils.py"
    click p10 "https://github.com/langchain-ai/openevals/tree/main/python/tests/"
    click p11 "https://github.com/langchain-ai/openevals/tree/main/python/openevals/code/e2b/sandbox/"

    %% Click Events for JavaScript/TypeScript Components
    click j1 "https://github.com/langchain-ai/openevals/blob/main/js/src/llm.ts"
    click j2 "https://github.com/langchain-ai/openevals/blob/main/js/src/json/match.ts"
    click j3 "https://github.com/langchain-ai/openevals/blob/main/js/src/string/levenshtein.ts"
    click j4 "https://github.com/langchain-ai/openevals/blob/main/js/src/string/embedding_similarity.ts"
    click j5 "https://github.com/langchain-ai/openevals/blob/main/js/src/code/llm.ts"
    click j6 "https://github.com/langchain-ai/openevals/tree/main/js/src/code/e2b/"
    click j7 "https://github.com/langchain-ai/openevals/blob/main/js/src/code/e2b/execution.ts"
    click j8 "https://github.com/langchain-ai/openevals/blob/main/js/src/code/e2b/typescript.ts"
    click j9 "https://github.com/langchain-ai/openevals/tree/main/js/src/prompts/"
    click j10 "https://github.com/langchain-ai/openevals/blob/main/js/src/utils.ts"
    click j11 "https://github.com/langchain-ai/openevals/tree/main/js/src/tests/"
    click j12 "https://github.com/langchain-ai/openevals/blob/main/js/langchain.config.js"

    %% Click Events for Shared Components and CI/CD / Assets
    click s1 "https://github.com/langchain-ai/openevals/tree/main/sandbox/e2b/"
    click s2 "https://github.com/langchain-ai/openevals/blob/main/.github/workflows/integration_tests.yml"
    click s3 "https://github.com/langchain-ai/openevals/tree/main/static/img"

    %% Styles
    classDef client fill:#ffe6f0,stroke:#cc0066,stroke-width:2px;
    classDef interface fill:#e6f7ff,stroke:#3399ff,stroke-width:2px;
    classDef evaluator fill:#ccf2ff,stroke:#3399ff,stroke-width:2px;
    classDef code fill:#fff2cc,stroke:#ff9900,stroke-width:2px;
    classDef sandbox fill:#ffd9b3,stroke:#ff6600,stroke-width:2px;
    classDef prompt fill:#e6ffe6,stroke:#33cc33,stroke-width:2px;
    classDef utility fill:#f2f2f2,stroke:#999999,stroke-width:2px;
    classDef test fill:#ffe6cc,stroke:#ff6600,stroke-width:2px;
    classDef config fill:#fff0f5,stroke:#ff66b3,stroke-width:2px;
    classDef cicd fill:#e6e6ff,stroke:#6666ff,stroke-width:2px;
    classDef asset fill:#f9f9f9,stroke:#cccccc,stroke-width:2px;
    classDef integration fill:#f0e6ff,stroke:#9933ff,stroke-width:2px;
    classDef external fill:#e0ffff,stroke:#00cccc,stroke-width:2px;
```
