Skip to content

notBlank ​

notBlank() fails an empty or whitespace-only answer. It is the cheapest guard against a target that returns nothing, so pair it with any metric that could pass on the absence of content.

ts
import { notBlank } from '@anvia/core/evals'

const metric = notBlank()

No expectation is required and case.expected is not read. The metric trims the output text and passes when at least one non-whitespace character remains.

OptionDefaultEffect
namenot_blankMetric name in scores and metricSummaries.
requiredtrueWhether a blank answer gates the case.
actualthe case outputSelector for the value to test.

Why it is separate from requiredFields ​

requiredFields inspects object keys; notBlank inspects text. An answer of " " or "" satisfies a schema that only checks for a string, so a suite that relies on schemaMatch alone can pass an empty payload. Add notBlank() when empty output is a failure rather than a valid answer.

The metric serializes non-string output the same way the text metrics do, so an object whose JSON is {} is not blank while null is.

A blank answer usually means the target failed silently. If you would rather record that as a failure of the target than of the requirement, assert it with maxLength or a predicate instead; invalid outcomes do not gate an application quality gate the same way a required failure does.

Built for Anvia.