mastra-ai/mastra · error · MastraError
INVALID_SCORER_THRESHOLD
INVALID_SCORER_THRESHOLD
Error message
${label} threshold for scorer "${scorerId}" must be a finite number between 0 and 1, got ${value} What it means
An INVALID_SCORER_THRESHOLD MastraError (domain SCORER, category USER) thrown by validateThresholdBound when a configured scorer threshold is not a finite number in [0, 1]. Thresholds compare scores to decide pass/fail, so out-of-range or non-finite values are rejected at configuration time.
Source
Thrown at packages/core/src/evals/thresholds.ts:34
export function checkThresholdPassed(score: number, threshold: ThresholdConfig): boolean {
if (!Number.isFinite(score)) {
return false;
}
if (typeof threshold === 'number') {
return score >= threshold;
}
if (threshold.min !== undefined && score < threshold.min) return false;
if (threshold.max !== undefined && score > threshold.max) return false;
return true;
}
export function isScorerWithThreshold<TScorer>(entry: ScorerEntry<TScorer>): entry is ScorerWithThreshold<TScorer> {
return typeof entry === 'object' && entry !== null && 'scorer' in entry && 'threshold' in entry;
}
function validateThresholdBound(value: number, label: string, scorerId: string): void {
if (!Number.isFinite(value) || value < 0 || value > 1) {
throw new MastraError({
domain: 'SCORER',
id: 'INVALID_SCORER_THRESHOLD',
category: 'USER',
text: `${label} threshold for scorer "${scorerId}" must be a finite number between 0 and 1, got ${value}`,
});
}
}
export function validateThresholdConfig(threshold: ThresholdConfig, scorerId: string): void {
if (typeof threshold === 'number') {
validateThresholdBound(threshold, 'Minimum', scorerId);
return;
}
if (typeof threshold !== 'object' || threshold === null || Array.isArray(threshold)) {
throw new MastraError({
domain: 'SCORER',
id: 'INVALID_SCORER_THRESHOLD',
category: 'USER',View on GitHub (pinned to 75dd419e61)
Solutions
- Set the threshold to a finite number between 0 and 1 (e.g. 0.7, not 70)
- If loading from config/env, parse and clamp/validate: Number.isFinite(v) && v >= 0 && v <= 1
- Check any threshold computation for NaN sources (division by zero, undefined inputs)
Example fix
// before
agents: { myAgent: { scoring: { myScorer: { threshold: 70 } } } }
// after
agents: { myAgent: { scoring: { myScorer: { threshold: 0.7 } } } } Defensive patterns
Strategy: validation
Validate before calling
function assertThreshold(v: unknown, label: string, scorerId: string): asserts v is number {
if (typeof v !== 'number' || !Number.isFinite(v) || v < 0 || v > 1) {
throw new Error(`${label} threshold for "${scorerId}" must be a finite number in [0,1], got ${v}`);
}
} Type guard
function isValidThreshold(v: unknown): v is number {
return typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 1;
} Try / catch
try {
validateThresholdConfig(scorerEntries);
} catch (e) {
if (e instanceof MastraError && e.id === 'INVALID_SCORER_THRESHOLD') {
logger.error('Bad scorer threshold in config', { detail: e.message });
} else throw e;
} Prevention
- Use fractions (0-1), not percentages, for thresholds
- Clamp/validate thresholds loaded from env or config files
- Guard computed thresholds against NaN (division by zero, undefined)
- Type thresholds as number and validate at config-load time
When it happens
Trigger: Defining a scorer entry with `threshold: -0.1`, `threshold: 1.5`, `threshold: NaN`, `threshold: Infinity`, or a non-numeric value coerced into a number field, then validating the threshold config via validateThresholdConfig.
Common situations: Typo in the threshold value; computing a threshold with a formula that yields NaN (e.g. division by zero) or a percentage (0-100) instead of a fraction (0-1); loading thresholds from env/JSON with wrong units.
Related errors
- AGENT_INPUT_PROCESSOR_ERROR
- AGENT_INPUT_STEP_PROCESSOR_ERROR
- AGENT_GENEREATE_SCORER_NOT_FOUND
- MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID
- MASTR_SCORER_FAILED_TO_RUN_MISSING_GENERATE_SCORE
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/ab858b186f7a5a2f.
Report an issue: GitHub.