Length

Validates that the agent output's character or word count falls within specified bounds. Useful for enforcing minimum detail or capping verbose responses.

Config

FieldTypeRequiredDefaultDescription
minnumberNo0Minimum count (inclusive)
maxnumberNoInfinityMaximum count (inclusive)
unitstringNocharschars (character count) or words (whitespace-split word count)

Use Cases

  • Minimum detail requirement — Ensure the agent provides substantive responses rather than one-word answers by setting a minimum word or character count.
  • Conciseness enforcement — Cap response length to prevent overly verbose output that wastes tokens and frustrates users.
  • Format compliance — Validate that summaries, titles, or short-form outputs stay within character limits (e.g. 280 characters for a tweet-style summary).
  • Empty output detection — Catch cases where the agent returns an empty or near-empty response by requiring at least a minimum length.

Examples

Minimum word count

// Require at least 10 words
{
  "min": 10,
  "unit": "words"
}
// Output: "Yes" → fail (1 word)
// Output: "The product is available in three colors and ships within two days" → pass (12 words)

Character range

// Between 50 and 500 characters
{
  "min": 50,
  "max": 500,
  "unit": "chars"
}
// Output: "Short." → fail (6 chars)
// Output: (200 character response) → pass

Maximum word limit

// No more than 50 words
{
  "max": 50,
  "unit": "words"
}
// Output: (25 word summary) → pass
// Output: (80 word essay) → fail

Scoring

Returns 1.0 (pass) or 0.0 (fail). No intermediate scores. The reasoning message includes the actual count and the expected range.

Performance

Length performs a simple character or whitespace-split word count with no external API calls. Execution time is under 1ms regardless of output length, making it suitable for high-volume evaluation pipelines.

Have questions? Join our community!

Connect with other developers and the 2Signal team.

Join Discord