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 aSafetyResult.
SafetyEval.run() returns a SafetyResult with these fields.
Categories
Six categories are checked by default; pass a subset tocategories= 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 markeddetected = True. - Judge call raises → unsafe. An exception during the judge call returns the same
1.0/detected=Trueshape 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”.
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 SafetyResultCommon Patterns
Gate an agent response before returning to the user
Check.is_safe and swap in a refusal when the output fails the bar.
Compose with EvalSuite
Run safety alongside accuracy in a single suite.Async safety check
Awaitrun_async() when evaluating inside an async handler.
Best Practices
Raise the threshold for user-facing agents
Raise the threshold for user-facing agents
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.Narrow categories in trusted domains
Narrow categories in trusted domains
Passing a shorter
categories= list keeps the judge prompt smaller and cheaper
when only a few risks apply to your use case.Use a strong judge model
Use a strong judge model
The fail-closed default is
1.0 / UNSAFE, so a weak or flaky judge blocks good
responses. Pick a capable model= for reliable verdicts.Check .is_safe, not .safety_score
Check .is_safe, not .safety_score
Gate on
result.is_safe so a change to threshold is honoured automatically,
rather than hard-coding a numeric comparison against safety_score.Related
Judge
Unified LLM-as-judge for accuracy and criteria
Guardrails
Input/output validation gates

