Skip to main content
Safety Eval runs an LLM-as-judge over agent output and blocks anything unsafe — with a fail-closed guarantee that a garbled judge verdict is never reported as safe.

Quick Start

1

Evaluate an agent

Point SafetyEval at an agent and an input prompt, then call run().
2

Narrow categories and tighten the threshold

Check only the categories you care about and raise the pass bar.
3

Evaluate pre-generated output

Pass output=... instead of an agent to score text you already have.
SafetyEval is the user-facing evaluator. The underlying LLM grader class is SafetyGrader — you rarely call it directly.

How It Works

The agent produces output, the safety judge scores each category, and the result is packaged into a SafetyResult. SafetyEval.run() returns a SafetyResult with these fields.

Categories

Six categories are checked by default; pass a subset to categories= to narrow the scan.

Fail-closed guarantee

An unsafe verdict is the default whenever the judge misbehaves — a green light is only ever produced by a verdict the parser actually read.
  • Unparsed verdict → unsafe. If the judge response can’t be parsed, the result is safety_score = 1.0, is_safe = False, and every requested category is marked detected = True.
  • Judge call raises → unsafe. An exception during the judge call returns the same 1.0 / detected=True shape rather than a silent pass.
  • Tolerant field matching. Markdown-bolded, lowercased, and bullet-prefixed labels (**Score:**, score:, - Score:) are read correctly, so ordinary model formatting never falls through to a false “safe”.
A strong judge model matters: the fail-closed default is 1.0 / UNSAFE, so a flaky judge blocks legitimate responses rather than leaking unsafe ones.

Configuration Options

Every parameter, type, and default is listed in the auto-generated SDK reference.

Eval API Reference

Full parameter reference for SafetyEval, SafetyGrader, and SafetyResult

Common Patterns

Gate an agent response before returning to the user

Check .is_safe and swap in a refusal when the output fails the bar.
The end-to-end flow:

Compose with EvalSuite

Run safety alongside accuracy in a single suite.

Async safety check

Await run_async() when evaluating inside an async handler.

Best Practices

The default threshold=7.0 is a starting point. Set it higher (8.0–9.0) for anything that reaches end users so borderline output is blocked.
Passing a shorter categories= list keeps the judge prompt smaller and cheaper when only a few risks apply to your use case.
The fail-closed default is 1.0 / UNSAFE, so a weak or flaky judge blocks good responses. Pick a capable model= for reliable verdicts.
Gate on result.is_safe so a change to threshold is honoured automatically, rather than hard-coding a numeric comparison against safety_score.

Judge

Unified LLM-as-judge for accuracy and criteria

Guardrails

Input/output validation gates