メインコンテンツへ移動

Quick Checks

Quick Checks は、一般的なアサーションに使える、LLM を使用しない合成可能なマイクロ Scorer です。既存の scorers: [...] 配列に追加でき、Scorer を使用できる場所なら runEvals、ライブスコアリング、実験、Studio のいずれでも利用できます。

内部的には標準の createScorer() インスタンスであるため、他の Scorer と同じ可観測性、ストレージ、パイプライン統合を備えています。

使用例
使用例への直接リンク

src/evals/weather-checks.ts
import { checks } from '@mastra/evals/checks'
import { runEvals } from '@mastra/core/evals'
import { myAgent } from '../agents'

const result = await runEvals({
data: [{ input: 'What is the weather in Brooklyn?' }],
target: myAgent,
scorers: [
checks.includes('sunny'),
checks.calledTool('get_weather'),
checks.toolOrder(['get_weather', 'summarize']),
checks.noToolErrors(),
],
})

console.log(result.scores)

テキストチェック
テキストチェックへの直接リンク

checks.includes(expected, options?)
checksincludesexpected-optionsへの直接リンク

Agent の出力テキストに指定した部分文字列が含まれる場合は 1、それ以外は 0 をスコアとして返します。

checks.includes('sunny')
checks.includes('Sunny', { ignoreCase: false })

expected:

string
出力内で検索する部分文字列。

options.ignoreCase?:

boolean
= true
大文字と小文字を区別せずに照合します。

戻り値:見つかった場合は 1、それ以外は 0

checks.excludes(unwanted, options?)
checksexcludesunwanted-optionsへの直接リンク

Agent の出力テキストに指定した部分文字列が含まれない場合は 1、それ以外は 0 をスコアとして返します。

checks.excludes('error')
checks.excludes('Error', { ignoreCase: false })

unwanted:

string
出力に含まれてはならない部分文字列。

options.ignoreCase?:

boolean
= true
大文字と小文字を区別せずに照合します。

戻り値:含まれない場合は 1、それ以外は 0

checks.equals(expected, options?)
checksequalsexpected-optionsへの直接リンク

任意の正規化後に、出力テキストが指定した文字列と完全に一致する場合は 1、それ以外は 0 をスコアとして返します。

checks.equals('Hello, world!')
checks.equals('Hello', { ignoreCase: false })

expected:

string
出力が完全に一致する必要がある文字列。

options.ignoreCase?:

boolean
= true
大文字と小文字を区別せずに照合します。

戻り値:一致する場合は 1、それ以外は 0

checks.matches(pattern, options?)
checksmatchespattern-optionsへの直接リンク

出力が正規表現に一致する場合は 1 をスコアとして返します。

checks.matches(/\d+°[FC]/)
checks.matches(/^hello$/, { exact: true })

pattern:

RegExp
出力との照合に使う正規表現。

options.exact?:

boolean
= false
パターンに ^ と $ を追加し、出力全体と一致するように固定します。

戻り値:一致する場合は 1、それ以外は 0

checks.similarity(expected, options?)
checkssimilarityexpected-optionsへの直接リンク

Dice 係数を使い、出力と指定した文字列の類似度スコア(0〜1)を返します。二値の 1 または 0 を返すようにするには、threshold を設定します。

checks.similarity('Sunny, 72°F')
checks.similarity('Sunny, 72°F', { threshold: 0.7 })

expected:

string
比較対象となる基準文字列。

options.threshold?:

number
1 を返すために必要な最小類似度スコア(0〜1)。省略した場合は、未加工の類似度スコアを返します。

options.ignoreCase?:

boolean
= true
大文字と小文字を区別せずに比較します。

戻り値:未加工の類似度スコア(0〜1)、または二値の 1 / 0threshold 設定時)。

Tool 呼び出しチェック
Tool 呼び出しチェックへの直接リンク

checks.calledTool(toolName, options?)
checkscalledtooltoolname-optionsへの直接リンク

Agent が指定した Tool を必要な回数以上呼び出した場合は 1 をスコアとして返します。

checks.calledTool('get_weather')
checks.calledTool('search', { times: 2 })

toolName:

string
検索する Tool の名前。

options.times?:

number
= 1
Tool を呼び出す必要がある最小回数。

戻り値:1times 回以上呼び出された場合)、それ以外は 0

checks.didNotCall(toolName)
checksdidnotcalltoolnameへの直接リンク

Agent が指定した Tool を呼び出さなかった場合は 1 をスコアとして返します。

checks.didNotCall('delete_user')

toolName:

string
出現してはならない Tool の名前。

戻り値:Tool が呼び出されなかった場合は 1、それ以外は 0

checks.toolOrder(expectedOrder)
checkstoolorderexpectedorderへの直接リンク

Tool が指定した順序で呼び出された場合は 1 をスコアとして返します。緩和された照合を使用するため、指定した Tool の間に別の Tool 呼び出しがあっても構いません。

checks.toolOrder(['search', 'summarize', 'respond'])

expectedOrder:

string[]
想定する呼び出し順の Tool 名。実際の Tool 呼び出しに部分列として現れる必要があります。

戻り値:指定した順序を満たす場合は 1、それ以外は 0

checks.maxToolCalls(max)
checksmaxtoolcallsmaxへの直接リンク

Agent による Tool 呼び出しが max 回以下の場合は 1 をスコアとして返します。

checks.maxToolCalls(5)

max:

number
許可する Tool 呼び出しの最大回数。

戻り値:上限以内の場合は 1、それ以外は 0

checks.usedNoTools()
checksusednotoolsへの直接リンク

Agent が Tool を一度も呼び出さなかった場合は 1 をスコアとして返します。

checks.usedNoTools()

戻り値:Tool が呼び出されなかった場合は 1、それ以外は 0

checks.noToolErrors()
checksnotoolerrorsへの直接リンク

どの Tool 呼び出しもエラー状態にならなかった場合は 1 をスコアとして返します。エラー結果(result.error が存在する場合)と未完了の Tool 呼び出し(state === 'call')の両方を検出します。

checks.noToolErrors()

戻り値:すべての Tool 呼び出しが成功した場合は 1、それ以外は 0

他の Scorer との組み合わせ
他の Scorer との組み合わせへの直接リンク

Checks は、同じ scorers 配列内で LLM ベースおよびコードベースの Scorer と組み合わせられます。

src/evals/combined-eval.ts
import { checks } from '@mastra/evals/checks'
import { createAnswerRelevancyScorer } from '@mastra/evals/scorers/prebuilt'
import { runEvals } from '@mastra/core/evals'
import { myAgent } from '../agents'

const result = await runEvals({
data: [{ input: 'What is the weather in Brooklyn?' }],
target: myAgent,
scorers: [
// Zero-LLM checks
checks.includes('Brooklyn'),
checks.calledTool('get_weather'),
checks.noToolErrors(),
// LLM-based scorer
createAnswerRelevancyScorer({ model: 'openai/gpt-5-mini' }),
],
})