Skip to main content
Output validation ensures your agent produces correct, well-formatted responses. You can validate content structure, exclude unwanted text, match patterns with regex, and use LLM-powered semantic evaluation.

Example

This example demonstrates how to validate agent outputs using multiple validators including content checks, format validation, timing, and usage metrics.

Eval Configuration

evals.yaml
In this example, we use output_text_tokens instead of output_tokens because the agent uses OpenAI (openai/gpt-5.2). For Anthropic models, use output_tokens instead. See Validating Token Usage for more details.

Agent Implementation

agent.py

Running Evaluations

How It Works

  1. Output Validation: Multiple validators check the agent’s response for required content (contains_all!), excluded content (not_contains!), and format (pattern!).
  2. Timing Validation: The elapsed validator ensures the agent responds within the specified time limit.
  3. Usage Validation: Span-level validators track resource consumption, such as token usage for LLM calls.
  4. Combined Validators: All validators must pass for the eval to succeed.

Evaluation Results

Successful Validation

When all validators pass:

Failed Validation

When any validator fails:

Key Features

  • Content Validation: Verify required keywords (contains_all!) and exclude unwanted content (not_contains!)
  • Format Validation: Ensure responses follow expected structure with pattern! regex validation
  • Time Validation: Monitor execution time with elapsed validators (lt!, lte!, etc.)
  • Usage Validation: Track resource consumption with span-level usage validators (e.g., llm.usage.output_text_tokens for OpenAI or llm.usage.output_tokens for Anthropic)
  • Combined Validators: Use multiple validators together - all must pass for the eval to succeed