examples/config-result-hooks/README.md
This example shows how to use extension hooks to process evaluation results programmatically. Use this to:
npx promptfoo@latest init --example config-result-hooks
npx promptfoo@latest eval
# promptfooconfig.yaml
extensions:
- file://result-handler.js:afterAll
# 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
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 |
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
}
result-handler.js - JavaScript handler with monitoring examplesresult-handler.py - Python handler with webhook integrationpromptfooconfig.yaml - Configuration using the extension