Install the SDK
Available evaluators
The SDK ships four evaluator classes inopenlit.evals:
Quickstart
Every evaluator follows the same two-step pattern: instantiate the class with your LLM provider settings, then call.measure() with the text you want to evaluate.
Constructor parameters
All four evaluator classes share the same constructor signature:str
default:"openai"
The LLM provider to use as the judge. Supported values:
"openai", "anthropic".str
The API key for the judge LLM provider. If omitted, the evaluator reads from the corresponding environment variable (
OPENAI_API_KEY or ANTHROPIC_API_KEY).str
The specific model to use. Defaults to
gpt-4o-mini for OpenAI and claude-3-opus-20240229 for Anthropic.str
An optional custom base URL for the LLM API. Useful for routing through a proxy or using an OpenAI-compatible endpoint.
dict[str, str]
A dictionary of additional evaluation categories to include beyond the built-in ones. Keys are category names and values are descriptions. The judge LLM uses these alongside the default categories.
float
default:"0.5"
The score cutoff (0–1) above which the
verdict is set to "yes" (failing). Lower values make the evaluator more sensitive.measure() parameters
All four evaluator classes share the same measure() signature:
str
default:""
The original user prompt that produced the response. Providing this gives the judge LLM additional context for scoring. Optional but recommended.
list[str]
A list of reference sentences or documents that the response should be faithful to. Used primarily by the hallucination evaluator to detect factual drift.
str
The LLM response text to evaluate. This is the primary input — the text that gets scored.
str
An optional unique identifier for the LLM completion being evaluated. When provided, the evaluation result is correlated with that response ID in the OpenLIT telemetry event.
Return value: JsonOutput
Every .measure() call returns a JsonOutput object with these fields:
Classification reference
- Hallucination
- Bias
- Toxicity
Custom categories
You can extend any evaluator with additional classification categories by passing acustom_categories dictionary. The judge LLM includes these alongside the built-in categories when scoring.
Use with OpenLIT tracing
When you initialize OpenLIT withopenlit.init(), evaluation results are automatically emitted as OpenTelemetry events alongside your traces. This means you can view programmatic evaluation scores directly in the OpenLIT dashboard without any additional configuration.
Evaluation events are emitted as OpenTelemetry Log Records by default. Set
evals_logs_export=False in openlit.init() to emit them as OTel Events instead, which is useful for backends that support events natively.LLM-as-a-judge
Automatically evaluate production traces without touching your application code
OpenGround
Compare LLM responses side-by-side to pick the best model for your use case
