When to use custom Scorers
Custom Scorers are the right tool when you need to check:- Domain-specific quality — output structure, required sections, or business-specific language rules
- Output format validation — confirm the agent returns valid JSON, a specific schema, or a parseable date
- Business rule compliance — block responses that mention restricted topics, competitor names, or regulated terminology
- Contextual safety — toxicity or bias checks calibrated to your specific user base and content policy
Create a Scorer
Open the Scorers view
In the Trident dashboard, navigate to Scorers in the left sidebar and click New Scorer.
Name and describe your Scorer
Enter a short name (for example,
no-system-prompt-leak) and a description that explains what the Scorer checks. The description appears alongside scores in the Traces view.Write your scorer function
Use the built-in JavaScript editor to write your
scorer function. The function receives a trace object and must return a number between 0 and 1. See the function signature and example below.Test against sample traces
Click Test to run your Scorer against recent traces from your project. The test panel shows the raw score and any errors, so you can iterate before saving.
Scorer function reference
Your scorer function receives a singletrace argument and must return a score from 0 to 1:
1.0— full pass0.0— full fail (creates a Finding with sourceSCORER)- Values between
0and1— partial score, flagged if below0.5
scorer.js
Available trace fields
| Field | Type | Description |
|---|---|---|
messages | array | Ordered array of { role, content } objects for the full conversation |
agentId | string | The agent identifier that produced this trace |
model | string | The model name used (for example, gpt-4o, claude-3-5-sonnet) |
latencyMs | number | End-to-end response latency in milliseconds |
tokenCount | object | { prompt, completion, total } token counts |
toolCalls | array | List of tool/function calls made during the trace |
metadata | object | Any custom metadata your SDK attached to the trace |
Score results in the dashboard
After a Scorer runs, its result appears on each trace in the Traces view:- A pass badge (score ≥ 0.5) in green
- A fail badge (score < 0.5) in red, with the numeric score
- Scores of exactly
0automatically create a Finding with sourceSCORER, severity determined by the Scorer’s configured severity level
Scorers run in a sandboxed Node.js VM with no network access, no filesystem access, and a hard execution limit of 200ms. If your function throws an error or exceeds the time limit, the trace receives a score of
null and a warning appears in the Scorer’s activity log.