Process and Route AI Evaluation Results Programmatically
Hook into AI evaluation lifecycle to process results, send metrics, trigger alerts, and integrate with CI/CD pipelines programmatically.
Why it matters
Automatically process AI evaluation results through custom hooks to send metrics to monitoring systems, trigger alerts based on performance thresholds, export data to custom formats, and integrate testing outcomes into CI/CD pipelines.
Outcomes
What it gets done
Send evaluation metrics to monitoring and observability systems
Trigger alerts when success rates fall below thresholds
Export test results to custom formats for reporting
Integrate evaluation outcomes into CI/CD pipeline workflows
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-config-result-hooks | bash Steps
Steps in the chain
Overview
Config Result Hooks
Extension hooks for processing promptfoo evaluation results When you need to programmatically route evaluation results to external systems like monitoring dashboards or CI/CD pipelines
What it does
This example shows how to use extension hooks to process evaluation results programmatically. It enables you to send metrics to monitoring systems, trigger alerts based on success rates, export data to custom formats, and integrate with CI/CD pipelines through four lifecycle hooks (beforeAll, beforeEach, afterEach, afterAll).
When to use - and when NOT to
Use this when you need to automatically route evaluation results to external systems - for example, posting metrics to monitoring systems after each test run, sending alerts when success rates drop below thresholds, or exporting results to custom formats for downstream analysis.
Do NOT use this if you only need to view results in the promptfoo UI or export to standard formats already supported natively. Avoid it if you're running one-off manual evaluations where manual review is sufficient.
Inputs and outputs
You configure extensions via YAML or CLI flags, pointing to handler files. The afterAll hook receives a context object containing:
{
evalId: string; // Unique evaluation ID
config: UnifiedConfig; // Full evaluation configuration
suite: TestSuite; // Test suite that was evaluated
results: EvaluateResult[]; // All individual test results
prompts: CompletedPrompt[]; // Prompts with metrics
}
You receive programmatic control over evaluation data at specific lifecycle points, allowing you to process, transform, or transmit results to any external system.
Integrations
Extensions can be configured via YAML or CLI flags:
# promptfooconfig.yaml
extensions:
- file://result-handler.js:afterAll
Or via CLI:
# Run with a one-off extension
promptfoo eval -x file://result-handler.js:afterAll
# Combine with config file extensions
promptfoo eval -x file://alert-on-failure.js:afterAll
The example includes result-handler.js (JavaScript handler with monitoring examples), result-handler.py (Python handler with webhook integration), and promptfooconfig.yaml configuration.
Who it's for
This is for teams building evaluation workflows who need to integrate test results into monitoring systems, alerting infrastructure, or CI/CD pipelines.
Quick start:
npx promptfoo@latest init --example config-result-hooks
npx promptfoo@latest eval
Source README
config-result-hooks (Process Evaluation Results)
This example shows how to use extension hooks to process evaluation results programmatically. Use this to:
- Send metrics to monitoring systems
- Trigger alerts based on success rates
- Export data to custom formats
- Integrate with CI/CD pipelines
Quick Start
npx promptfoo@latest init --example config-result-hooks
npx promptfoo@latest eval
Usage
Via Configuration File
### promptfooconfig.yaml
extensions:
- file://result-handler.js:afterAll
Via CLI Flag
### Run with a one-off extension
promptfoo eval -x file://result-handler.js:afterAll
### Combine with config file extensions
promptfoo eval -x file://alert-on-failure.js:afterAll
Extension Hooks
Extensions support four lifecycle hooks:
| Hook | When Called | Use Case |
|---|---|---|
beforeAll |
Before evaluation starts | Modify test suite, validate config |
beforeEach |
Before each test case | Customize test parameters |
afterEach |
After each test case | Process individual results |
afterAll |
After all tests complete | Aggregate results, send reports |
afterAll Context
The afterAll hook receives:
{
evalId: string; // Unique evaluation ID
config: UnifiedConfig; // Full evaluation configuration
suite: TestSuite; // Test suite that was evaluated
results: EvaluateResult[]; // All individual test results
prompts: CompletedPrompt[]; // Prompts with metrics
}
Examples in this Directory
result-handler.js- JavaScript handler with monitoring examplesresult-handler.py- Python handler with webhook integrationpromptfooconfig.yaml- Configuration using the extension
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.