Skip to main content
The evaluate() function is the single entrypoint for all evaluations in the ai-evaluation SDK. It automatically routes to the right engine based on what you pass.

Installation

Quick Start


How Engine Routing Works

You don’t need to think about engines — evaluate() figures it out: You can also force an engine with engine="local", engine="turing", or engine="llm".

Function Signature

EvalResult

Every evaluation returns an EvalResult:

BatchResult

When you pass a list of eval names, you get a BatchResult:

Local Metrics (No API Key)

These run instantly on your machine. No network calls, no API keys.

String Checks

Similarity Metrics

Scores are continuous 0.0–1.0:

Hallucination Detection

Uses NLI model when available (pip install ai-evaluation[nli]), falls back to heuristics:

RAG Metrics

For evaluating Retrieval-Augmented Generation pipelines:

Guardrails (Security)

Block attacks in <10ms:

Complete Metrics Reference

Every metric below works through evaluate(). Scores are 0.0—1.0 unless noted otherwise. Binary metrics return exactly 0 or 1.
Deterministic, regex-based checks. All scores are binary (0 or 1). No API key or model required.Examples:
Validate JSON structure, schema compliance, and syntax. All scores are binary.Examples:
Continuous scores from 0.0 to 1.0 measuring textual or semantic similarity. No API key required.
embedding_similarity and semantic_list_contains use sentence-transformers. Install with pip install ai-evaluation[nli].
Examples:
Detect fabricated, unsupported, or contradictory claims. Uses a DeBERTa NLI model when available, falls back to heuristics. All support augment=True for LLM refinement.
For best accuracy, install the NLI model: pip install ai-evaluation[nli]. Without it, a keyword-based heuristic is used with a warning.
Examples:
Evaluate LLM function/tool calling accuracy. Output and expected_output should be JSON strings representing function calls.Examples:
Evaluate autonomous agent behavior across multi-step trajectories. Output should be a trajectory JSON (list of steps), and expected_output should describe the goal/task.Examples:
Evaluate the retrieval step of RAG pipelines. Measures how well retrieved context matches the query and ground truth.Examples:
Evaluate the generation step of RAG pipelines. Measures how well the LLM answer uses and stays faithful to the retrieved context.Examples:
Advanced RAG capabilities: multi-hop reasoning, source attribution, and citation checking.Examples:
Aggregate scores that combine multiple RAG sub-metrics into a single number.Examples:
Evaluate JSON, YAML, and other structured outputs for correctness, completeness, and schema compliance.Examples:
Fast security scanners accessible through evaluate(). All run locally in <10ms. For the full scanner pipeline API, see the Guardrails Guide.Examples:
For advanced guardrails (scanner pipelines, model-based screening, ensembles), use the scanner API directly. See the Guardrails Guide for full details.

Cloud Evaluations (Turing Models)

Use Future AGI’s purpose-built evaluation models for production-grade accuracy.
Requires FI_API_KEY and FI_SECRET_KEY. Get them from Admin Settings.
Available Turing models: turing_flash, turing_small.

LLM-as-Judge (Custom Criteria)

Write your own evaluation criteria and use any LLM as the judge. Works with Gemini, GPT-4, Claude, Llama, or any model supported by LiteLLM.

Supported Models

Any LiteLLM model string works:
Set the corresponding API key as an environment variable (GOOGLE_API_KEY, OPENAI_API_KEY, etc.).

Using Placeholders

Your prompt can reference any input field with {field_name}:

Multimodal Evaluation (Images & Audio)

Pass image or audio URLs directly to the LLM judge. The model sees the actual media, not just the URL text.
Requires a vision/audio-capable model like gemini/gemini-2.5-flash or gpt-4o.

Image Evaluation

Comparing Two Images

Audio Evaluation

Supported Media Keys


Auto-Generate Grading Criteria

Don’t want to write a detailed rubric? Describe what you want to evaluate in plain English, and the LLM generates the criteria for you.
You can also generate criteria separately:
Generated criteria are cached per session, so repeated calls with the same description are instant.

LLM Augmentation

Run a fast local heuristic first, then have an LLM refine the judgment. Best of both worlds: speed of local metrics + accuracy of LLM judges.

How It Works

  1. Local metric runs first (faithfulness heuristic) → produces initial score + reasoning
  2. LLM receives the original inputs + the heuristic’s analysis
  3. LLM produces a refined score with better nuance

Which Metrics Support Augmentation?

Metrics with supports_llm_judge = True:
  • faithfulness
  • hallucination_score
  • task_completion
  • action_safety
  • reasoning_quality
  • claim_support
  • factual_consistency

Feedback Loop

Submit corrections when the judge gets it wrong. Future evaluations use your corrections as few-shot examples, improving accuracy over time.

Feedback Stores

Two stores are available:

Correcting Results

ChromaFeedbackStore requires the feedback extra: pip install ai-evaluation[feedback]. InMemoryFeedbackStore works with the base install.

OpenTelemetry Tracing

Wire evaluation scores into your observability stack (Jaeger, Datadog, Grafana).
See the Tracing Guide for full setup with exporters.

Streaming Evaluation

Monitor LLM output token-by-token in real time. Detect toxicity, PII, jailbreaks, and quality degradation mid-generation with configurable early stopping.

Basic Usage

Factory Methods

Use pre-configured evaluators for common scenarios:

Early Stop Policies

Control when generation should be halted:

Built-in Scorers

Async Streaming (e.g., OpenAI)

StreamingConfig Options

Key configuration fields:

Environment Variables


Error Handling